Example usage for javafx.scene.image ImageView getImage

List of usage examples for javafx.scene.image ImageView getImage

Introduction

In this page you can find the example usage for javafx.scene.image ImageView getImage.

Prototype

public final Image getImage() 

Source Link

Usage

From source file:Main.java

/**
 * Creates an image canvas with the given width and height.
 *//*from   ww  w . j  a v  a 2s . co m*/
public static Canvas createImageCanvas(String url, double width, double height) {
    ImageView img = new ImageView(new Image(url, width, height, false, true));
    final Canvas canvas = new Canvas(width, height);
    final GraphicsContext gc = canvas.getGraphicsContext2D();
    gc.drawImage(img.getImage(), 0, 0);

    return canvas;
}

From source file:net.rptools.tokentool.util.ImageUtil.java

public static double getScaleXRatio(ImageView imageView) {
    return imageView.getBoundsInParent().getWidth() / imageView.getImage().getWidth();
}

From source file:net.rptools.tokentool.util.ImageUtil.java

public static double getScaleYRatio(ImageView imageView) {
    return imageView.getBoundsInParent().getHeight() / imageView.getImage().getHeight();
}

From source file:net.rptools.tokentool.controller.ManageOverlays_Controller.java

private void updateDetails(File overlayFile, ImageView overlayImage, boolean selected) {
    if (selected) {
        int w = (int) overlayImage.getImage().getWidth();
        int h = (int) overlayImage.getImage().getHeight();

        overlayName.setText(FilenameUtils.getBaseName(overlayFile.getName()));
        overlayDescription.setText(ImageUtil.getFileType(overlayFile));
        overlayDimensions.setText(w + " x " + h);
        overlayLayerImage.setImage(overlayImage.getImage());
        ;/*ww  w .  ja v a  2 s.  co  m*/

        try {
            overlayLayerMask = ImageUtil.getMaskImage(overlayLayerMask, overlayFile.toPath());
        } catch (IOException e) {
            log.error("Updating details for: " + overlayFile.getAbsolutePath(), e);
        }
    } else {
        clearDetails();
    }
}

From source file:net.rptools.tokentool.util.ImageUtil.java

public static Image composePreview(StackPane compositeTokenPane, Color bgColor, ImageView portraitImageView,
        ImageView maskImageView, ImageView overlayImageView, boolean useAsBase, boolean clipImage) {
    // Process layout as maskImage may have changed size if the overlay was changed
    compositeTokenPane.layout();// w  w  w  .jav a2s  .  com
    SnapshotParameters parameter = new SnapshotParameters();
    Image finalImage = null;
    Group blend;

    if (clipImage) {
        // We need to clip the portrait image first then blend the overlay image over it
        // We will first get a snapshot of the portrait equal to the mask overlay image width/height
        double x, y, width, height;

        x = maskImageView.getParent().getLayoutX();
        y = maskImageView.getParent().getLayoutY();
        width = maskImageView.getFitWidth();
        height = maskImageView.getFitHeight();

        Rectangle2D viewPort = new Rectangle2D(x, y, width, height);
        Rectangle2D maskViewPort = new Rectangle2D(1, 1, width, height);
        WritableImage newImage = new WritableImage((int) width, (int) height);
        WritableImage newMaskImage = new WritableImage((int) width, (int) height);

        ImageView overlayCopyImageView = new ImageView();
        ImageView clippedImageView = new ImageView();

        parameter.setViewport(viewPort);
        parameter.setFill(bgColor);
        portraitImageView.snapshot(parameter, newImage);

        parameter.setViewport(maskViewPort);
        parameter.setFill(Color.TRANSPARENT);
        maskImageView.setVisible(true);
        maskImageView.snapshot(parameter, newMaskImage);
        maskImageView.setVisible(false);

        clippedImageView.setFitWidth(width);
        clippedImageView.setFitHeight(height);
        clippedImageView.setImage(clipImageWithMask(newImage, newMaskImage));

        // Our masked portrait image is now stored in clippedImageView, lets now blend the overlay image over it
        // We'll create a temporary group to hold our temporary ImageViews's and blend them and take a snapshot
        overlayCopyImageView.setImage(overlayImageView.getImage());
        overlayCopyImageView.setFitWidth(overlayImageView.getFitWidth());
        overlayCopyImageView.setFitHeight(overlayImageView.getFitHeight());
        overlayCopyImageView.setOpacity(overlayImageView.getOpacity());

        if (useAsBase) {
            blend = new Group(overlayCopyImageView, clippedImageView);
        } else {
            blend = new Group(clippedImageView, overlayCopyImageView);
        }

        // Last, we'll clean up any excess transparent edges by cropping it
        finalImage = autoCropImage(blend.snapshot(parameter, null));
    } else {
        parameter.setFill(Color.TRANSPARENT);
        finalImage = autoCropImage(compositeTokenPane.snapshot(parameter, null));
    }

    return finalImage;
}