use of javafx.scene.image.WritableImage in project processing by processing.
the class PGraphicsFX2D method loadPixels.
// //////////////////////////////////////////////////////////////
//
// // COLOR MODE
//
// // All colorMode() variations are inherited from PGraphics.
//
//
//
// //////////////////////////////////////////////////////////////
//
// // COLOR CALC
//
// // colorCalc() and colorCalcARGB() inherited from PGraphics.
//
//
//
// //////////////////////////////////////////////////////////////
//
// // COLOR DATATYPE STUFFING
//
// // final color() variations inherited.
//
//
//
// //////////////////////////////////////////////////////////////
//
// // COLOR DATATYPE EXTRACTION
//
// // final methods alpha, red, green, blue,
// // hue, saturation, and brightness all inherited.
//
//
//
// //////////////////////////////////////////////////////////////
//
// // COLOR DATATYPE INTERPOLATION
//
// // both lerpColor variants inherited.
//
//
//
// //////////////////////////////////////////////////////////////
//
// // BEGIN/END RAW
//
//
// @Override
// public void beginRaw(PGraphics recorderRaw) {
// showMethodWarning("beginRaw");
// }
//
//
// @Override
// public void endRaw() {
// showMethodWarning("endRaw");
// }
//
//
//
// //////////////////////////////////////////////////////////////
//
// // WARNINGS and EXCEPTIONS
//
// // showWarning and showException inherited.
//
//
//
// //////////////////////////////////////////////////////////////
//
// // RENDERER SUPPORT QUERIES
//
//
// //public boolean displayable() // true
//
//
// //public boolean is2D() // true
//
//
// //public boolean is3D() // false
//////////////////////////////////////////////////////////////
// PIMAGE METHODS
@Override
public void loadPixels() {
if ((pixels == null) || (pixels.length != pixelWidth * pixelHeight)) {
pixels = new int[pixelWidth * pixelHeight];
loaded = false;
}
if (!loaded) {
if (snapshotImage == null || snapshotImage.getWidth() != pixelWidth || snapshotImage.getHeight() != pixelHeight) {
snapshotImage = new WritableImage(pixelWidth, pixelHeight);
}
SnapshotParameters sp = new SnapshotParameters();
if (pixelDensity != 1) {
sp.setTransform(Transform.scale(pixelDensity, pixelDensity));
}
snapshotImage = ((PSurfaceFX) surface).canvas.snapshot(sp, snapshotImage);
PixelReader pr = snapshotImage.getPixelReader();
pr.getPixels(0, 0, pixelWidth, pixelHeight, argbFormat, pixels, 0, pixelWidth);
loaded = true;
modified = false;
}
}
use of javafx.scene.image.WritableImage in project processing by processing.
the class PSurfaceFX method setCursor.
public void setCursor(PImage image, int hotspotX, int hotspotY) {
int w = image.pixelWidth;
int h = image.pixelHeight;
WritableImage im = new WritableImage(w, h);
im.getPixelWriter().setPixels(0, 0, w, h, PixelFormat.getIntArgbInstance(), image.pixels, 0, w);
ImageCursor c = new ImageCursor(im, hotspotX, hotspotY);
lastCursor = c;
canvas.getScene().setCursor(c);
}
use of javafx.scene.image.WritableImage in project processing by processing.
the class PSurfaceFX method setIcon.
public void setIcon(PImage icon) {
int w = icon.pixelWidth;
int h = icon.pixelHeight;
WritableImage im = new WritableImage(w, h);
im.getPixelWriter().setPixels(0, 0, w, h, PixelFormat.getIntArgbInstance(), icon.pixels, 0, w);
Stage stage = (Stage) canvas.getScene().getWindow();
stage.getIcons().clear();
stage.getIcons().add(im);
}
use of javafx.scene.image.WritableImage in project jphp by jphp-compiler.
the class DraggableTab method updateGraphic.
public void updateGraphic() {
setGraphic(nameLabel);
Platform.runLater(new Runnable() {
@Override
public void run() {
SnapshotParameters snapParams = new SnapshotParameters();
snapParams.setFill(Color.TRANSPARENT);
WritableImage snapshot = nameLabel.snapshot(snapParams, null);
nameLabelSnapshot.setAutoSize(true);
nameLabelSnapshot.setImage(snapshot);
setGraphic(nameLabelSnapshot);
}
});
}
use of javafx.scene.image.WritableImage in project jphp by jphp-compiler.
the class UXCanvas method writeImageAsync.
@Signature
public void writeImageAsync(final String format, final Memory outputStream, @Nullable final javafx.scene.paint.Color transparentColor, @Nullable final Invoker callback, final Environment env) throws IOException {
Platform.runLater(() -> {
SnapshotParameters param = new SnapshotParameters();
param.setDepthBuffer(true);
param.setFill(javafx.scene.paint.Color.TRANSPARENT);
try {
final WritableImage image = getWrappedObject().snapshot(param, null);
new Thread(() -> {
BufferedImage bImage = SwingFXUtils.fromFXImage(image, null);
if (transparentColor != null) {
final int markerRGB = new Color((int) (transparentColor.getRed() * 255), (int) (transparentColor.getGreen() * 255), (int) (transparentColor.getBlue() * 255)).getRGB();
ImageFilter filter = new RGBImageFilter() {
public final int filterRGB(int x, int y, int rgb) {
if (markerRGB == rgb) {
return 0x00FFFFFF & rgb;
} else {
return rgb;
}
}
};
ImageProducer ip = new FilteredImageSource(bImage.getSource(), filter);
Image image1 = Toolkit.getDefaultToolkit().createImage(ip);
bImage = imageToBufferedImage(image1);
}
try {
OutputStream out = Stream.getOutputStream(env, outputStream);
if (out == null) {
throw new IOException();
}
ImageIO.write(bImage, format, out);
if (callback != null) {
Platform.runLater(() -> callback.callAny(true));
}
Stream.closeStream(env, out);
} catch (IOException e) {
if (callback != null) {
Platform.runLater(() -> callback.callAny(false));
}
env.wrapThrow(e);
}
}).start();
} catch (IllegalArgumentException e) {
;
}
});
}
Aggregations