Search in sources :

Example 66 with WritableImage

use of javafx.scene.image.WritableImage in project jphp by jphp-compiler.

the class UXCanvas method save.

@Signature
public void save(Environment env, Memory stream, String format) throws IOException, InvocationTargetException, InterruptedException {
    SnapshotParameters param = new SnapshotParameters();
    param.setDepthBuffer(true);
    param.setFill(javafx.scene.paint.Color.TRANSPARENT);
    try {
        final WritableImage image = getWrappedObject().snapshot(param, null);
        BufferedImage bImage = SwingFXUtils.fromFXImage(image, null);
        try {
            OutputStream out = Stream.getOutputStream(env, stream);
            if (out == null) {
                throw new IOException();
            }
            try {
                ImageIO.write(bImage, format, out);
            } finally {
                Stream.closeStream(env, out);
            }
        } catch (IOException e) {
            env.wrapThrow(e);
        }
    } catch (IllegalArgumentException e) {
        ;
    }
}
Also used : WritableImage(javafx.scene.image.WritableImage) SnapshotParameters(javafx.scene.SnapshotParameters) OutputStream(java.io.OutputStream) IOException(java.io.IOException) Signature(php.runtime.annotation.Reflection.Signature)

Example 67 with WritableImage

use of javafx.scene.image.WritableImage in project jphp by jphp-compiler.

the class UXNode method snapshot.

@Signature
public UXImage snapshot(Environment env) {
    SnapshotParameters snapParams = new SnapshotParameters();
    snapParams.setFill(Color.TRANSPARENT);
    WritableImage snapshot = getWrappedObject().snapshot(snapParams, null);
    return snapshot == null ? null : new UXImage(env, snapshot);
}
Also used : WritableImage(javafx.scene.image.WritableImage)

Example 68 with WritableImage

use of javafx.scene.image.WritableImage in project jphp by jphp-compiler.

the class ImageViewEx method update.

protected void update() {
    if (autoSize) {
        setWidth(image == null ? 0 : image.getWidth());
        setHeight(image == null ? 0 : image.getHeight());
    }
    g2.clearRect(0, 0, getWidth(), getHeight());
    if (background != null) {
        g2.setFill(background);
        g2.fillRect(0, 0, getWidth(), getHeight());
    }
    if (image != null) {
        double x = 0, y = 0, w = image.getWidth(), h = image.getHeight();
        if (isMosaic()) {
            int horCount = (int) Math.ceil(getWidth() / w + mosaicGap);
            int verCount = (int) Math.ceil(getHeight() / h + mosaicGap);
            int startX = 0;
            int startY = 0;
            for (int i = startY; i < verCount; i++) {
                for (int j = startX; j < horCount; j++) {
                    g2.drawImage(image, j * w + (j * mosaicGap), i * h + (i * mosaicGap), w, h);
                }
            }
        } else {
            if (isStretch()) {
                if (!smartStretch || (w > getWidth() || h > getHeight())) {
                    if (isProportional()) {
                        double ratio = Math.min(getWidth() / w, getHeight() / h);
                        w = (int) (w * ratio);
                        h = (int) (h * ratio);
                    } else {
                        w = getWidth();
                        h = getHeight();
                    }
                }
            }
            if (isCentered()) {
                x = Math.round(getWidth() / 2 - w / 2);
                y = Math.round(getHeight() / 2 - h / 2);
            }
            if (isStretch() && (flipX || flipY)) {
                Canvas canvas = new Canvas();
                canvas.setWidth(w);
                canvas.setHeight(h);
                GraphicsContext g2_tmp = canvas.getGraphicsContext2D();
                g2_tmp.drawImage(image, x, y, w, h);
                SnapshotParameters snapshotParameters = new SnapshotParameters();
                snapshotParameters.setFill(Color.TRANSPARENT);
                WritableImage snapshot = canvas.snapshot(snapshotParameters, null);
                g2.drawImage(snapshot, x, y, w, h, flipX ? w : 0, flipY ? h : 0, w * (flipX ? -1 : 1), h * (flipY ? -1 : 1));
            } else {
                if (flipX || flipY) {
                    g2.drawImage(image, x, y, w, h, flipX ? w : 0, flipY ? h : 0, w * (flipX ? -1 : 1), h * (flipY ? -1 : 1));
                } else {
                    g2.drawImage(image, x, y, w, h);
                }
            }
        }
    }
    if (text != null && !text.trim().isEmpty()) {
        g2.setFont(font);
        g2.setFill(textFill);
        double fWidth = UXFont.calculateTextWidth(text, font);
        double fHeight = UXFont.getLineHeight(font);
        g2.fillText(text, getWidth() / 2 - fWidth / 2, getHeight() / 2 + fHeight / 4, getWidth());
    }
}
Also used : WritableImage(javafx.scene.image.WritableImage) SnapshotParameters(javafx.scene.SnapshotParameters) GraphicsContext(javafx.scene.canvas.GraphicsContext) Canvas(javafx.scene.canvas.Canvas) Paint(javafx.scene.paint.Paint)

Example 69 with WritableImage

use of javafx.scene.image.WritableImage in project jphp by jphp-compiler.

the class DnDTabPaneSkin method tabPane_handleDragStart.

void tabPane_handleDragStart(MouseEvent event) {
    try {
        // $NON-NLS-1$
        Field f_tab = event.getSource().getClass().getDeclaredField("tab");
        f_tab.setAccessible(true);
        Tab t = (Tab) f_tab.get(event.getSource());
        if (t != null && efx_canStartDrag(t)) {
            DRAGGED_TAB = t;
            Node node = (Node) event.getSource();
            Dragboard db = node.startDragAndDrop(TransferMode.MOVE);
            WritableImage snapShot = node.snapshot(new SnapshotParameters(), null);
            PixelReader reader = snapShot.getPixelReader();
            int padX = 10;
            int padY = 10;
            int width = (int) snapShot.getWidth();
            int height = (int) snapShot.getHeight();
            WritableImage image = new WritableImage(width + padX, height + padY);
            PixelWriter writer = image.getPixelWriter();
            int h = 0;
            int v = 0;
            while (h < width + padX) {
                v = 0;
                while (v < height + padY) {
                    if (h >= padX && h <= width + padX && v >= padY && v <= height + padY) {
                        writer.setColor(h, v, reader.getColor(h - padX, v - padY));
                    } else {
                        writer.setColor(h, v, Color.TRANSPARENT);
                    }
                    v++;
                }
                h++;
            }
            db.setDragView(image, image.getWidth(), image.getHeight() * -1);
            ClipboardContent content = new ClipboardContent();
            String data = efx_getClipboardContent(t);
            if (data != null) {
                content.put(TAB_MOVE, data);
            }
            db.setContent(content);
        }
    } catch (Throwable t) {
        // // TODO Auto-generated catch block
        t.printStackTrace();
    }
}
Also used : Field(java.lang.reflect.Field) WritableImage(javafx.scene.image.WritableImage) Tab(javafx.scene.control.Tab) SnapshotParameters(javafx.scene.SnapshotParameters) PixelReader(javafx.scene.image.PixelReader) ClipboardContent(javafx.scene.input.ClipboardContent) Node(javafx.scene.Node) PixelWriter(javafx.scene.image.PixelWriter) Dragboard(javafx.scene.input.Dragboard)

Example 70 with WritableImage

use of javafx.scene.image.WritableImage in project JFoenix by jfoenixadmin.

the class ExtendedAnimatedFlowContainer method updatePlaceholder.

private void updatePlaceholder(Node newView) {
    if (view.getWidth() > 0 && view.getHeight() > 0) {
        SnapshotParameters parameters = new SnapshotParameters();
        parameters.setFill(Color.TRANSPARENT);
        Image placeholderImage = view.snapshot(parameters, new WritableImage((int) view.getWidth(), (int) view.getHeight()));
        placeholder.setImage(placeholderImage);
        placeholder.setFitWidth(placeholderImage.getWidth());
        placeholder.setFitHeight(placeholderImage.getHeight());
    } else {
        placeholder.setImage(null);
    }
    placeholder.setVisible(true);
    placeholder.setOpacity(1.0);
    view.getChildren().setAll(placeholder, newView);
    placeholder.toFront();
}
Also used : WritableImage(javafx.scene.image.WritableImage) SnapshotParameters(javafx.scene.SnapshotParameters) WritableImage(javafx.scene.image.WritableImage) Image(javafx.scene.image.Image)

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