Search in sources :

Example 1 with WritableImage

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;
    }
}
Also used : WritableImage(javafx.scene.image.WritableImage) SnapshotParameters(javafx.scene.SnapshotParameters) PixelReader(javafx.scene.image.PixelReader)

Example 2 with WritableImage

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);
}
Also used : WritableImage(javafx.scene.image.WritableImage) ImageCursor(javafx.scene.ImageCursor)

Example 3 with WritableImage

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);
}
Also used : WritableImage(javafx.scene.image.WritableImage) Stage(javafx.stage.Stage)

Example 4 with WritableImage

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);
        }
    });
}
Also used : WritableImage(javafx.scene.image.WritableImage) SnapshotParameters(javafx.scene.SnapshotParameters)

Example 5 with WritableImage

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) {
            ;
        }
    });
}
Also used : OutputStream(java.io.OutputStream) IOException(java.io.IOException) WritableImage(javafx.scene.image.WritableImage) WritableImage(javafx.scene.image.WritableImage) SnapshotParameters(javafx.scene.SnapshotParameters) Signature(php.runtime.annotation.Reflection.Signature)

Aggregations

WritableImage (javafx.scene.image.WritableImage)74 SnapshotParameters (javafx.scene.SnapshotParameters)26 PixelWriter (javafx.scene.image.PixelWriter)23 PixelReader (javafx.scene.image.PixelReader)13 IOException (java.io.IOException)12 Color (javafx.scene.paint.Color)11 BufferedImage (java.awt.image.BufferedImage)9 File (java.io.File)8 Image (javafx.scene.image.Image)7 ImageView (javafx.scene.image.ImageView)7 Point2D (javafx.geometry.Point2D)6 Group (javafx.scene.Group)5 Random (java.util.Random)4 Canvas (javafx.scene.canvas.Canvas)4 GraphicsContext (javafx.scene.canvas.GraphicsContext)4 Texture (com.almasb.fxgl.texture.Texture)3 OutputStream (java.io.OutputStream)3 Scene (javafx.scene.Scene)3 Background (javafx.scene.layout.Background)3 Scale (javafx.scene.transform.Scale)3