List of usage examples for javafx.scene SnapshotParameters SnapshotParameters
public SnapshotParameters()
From source file:ijfx.ui.previewToolbar.DefaultWidget.java
@Override public Image getImage(PreviewService previewService, int size) { if (image != null) return image; if (previewService == null) return null; if (previewService.getImageDisplayService().getActiveDataset() == null) { return null; } else if (this.getIcon().equals("preview")) { try {// w w w . j av a 2s . c om previewService.setParameters(-1, -1, size, size); return previewService.getImageDisplay(action, this.getParameters()); } catch (Exception e) { e.printStackTrace(); FontAwesomeIconView fontAwesomeIconView = new FontAwesomeIconView(FontAwesomeIcon.AMBULANCE); return FontAwesomeIconUtils.FAItoImage(fontAwesomeIconView, size); } } else if (getIcon().startsWith("char:")) { Canvas canvas = new Canvas(size, size); GraphicsContext graphicsContext2D = canvas.getGraphicsContext2D(); graphicsContext2D.setFill(Color.WHITE); graphicsContext2D.setFont(javafx.scene.text.Font.font("Arial", size)); graphicsContext2D.fillText(getIcon().substring(5), size / 3, size * 0.8); final SnapshotParameters params = new SnapshotParameters(); params.setFill(Color.TRANSPARENT); // final WritableImage snapshot = canvas.snapshot(params, null); Task<WritableImage> getIcon = new CallbackTask<Canvas, WritableImage>(canvas) .run(input -> input.snapshot(params, null)); Platform.runLater(getIcon); try { // Image image = new Ima image = getIcon.get(); return image; } catch (InterruptedException ex) { Logger.getLogger(DefaultWidget.class.getName()).log(Level.SEVERE, null, ex); } catch (ExecutionException ex) { Logger.getLogger(DefaultWidget.class.getName()).log(Level.SEVERE, null, ex); } return null; } //Check if icon exist in Enumeration else if (Arrays.stream(FontAwesomeIcon.values()).filter(e -> e.name().equals(icon)).count() > 0) { FontAwesomeIconView fontAwesomeIconView = new FontAwesomeIconView(FontAwesomeIcon.valueOf(icon)); return FontAwesomeIconUtils.FAItoImage(fontAwesomeIconView, size); } else { image = new Image(getClass().getResource(icon).toExternalForm(), size, size, true, true); return image; } }
From source file:io.github.mzmine.util.jfreechart.JFreeChartUtils.java
public static void exportToClipboard(ChartViewer chartNode) { final Clipboard clipboard = Clipboard.getSystemClipboard(); final ClipboardContent content = new ClipboardContent(); final int width = (int) chartNode.getWidth(); final int height = (int) chartNode.getHeight(); WritableImage img = new WritableImage(width, height); SnapshotParameters params = new SnapshotParameters(); chartNode.snapshot(params, img);/*www .j av a 2 s. c o m*/ content.putImage(img); clipboard.setContent(content); }
From source file:net.rptools.image.listeners.DrawHandler.java
/** * Convert the shape into an image for storage in the layer model. *///from w w w . ja v a2 s . c o m @ThreadPolicy(ThreadPolicy.ThreadId.JFX) private void finalizeDrawing() { final SnapshotParameters params = new SnapshotParameters(); params.setFill(Color.TRANSPARENT); final WritableImage snapshot = currentShape.snapshot(params, null); final Bounds bounds = currentShape.getBoundsInParent(); getLayer().addImage(snapshot, bounds.getMinX(), bounds.getMinY()); getLayer().getDrawable().getChildren().remove(currentShape); }
From source file:net.rptools.tokentool.util.ImageUtil.java
private static Image autoCropImage(Image imageSource) { ImageView croppedImageView = new ImageView(imageSource); PixelReader pixelReader = imageSource.getPixelReader(); int imageWidth = (int) imageSource.getWidth(); int imageHeight = (int) imageSource.getHeight(); int minX = imageWidth, minY = imageHeight, maxX = 0, maxY = 0; // Find the first and last pixels that are not transparent to create a bounding viewport for (int readY = 0; readY < imageHeight; readY++) { for (int readX = 0; readX < imageWidth; readX++) { Color pixelColor = pixelReader.getColor(readX, readY); if (!pixelColor.equals(Color.TRANSPARENT)) { if (readX < minX) minX = readX;//ww w. j a v a 2 s.c o m if (readX > maxX) maxX = readX; if (readY < minY) minY = readY; if (readY > maxY) maxY = readY; } } } if (maxX - minX <= 0 || maxY - minY <= 0) return new WritableImage(1, 1); // Create a viewport to clip the image using snapshot Rectangle2D viewPort = new Rectangle2D(minX, minY, maxX - minX, maxY - minY); SnapshotParameters parameter = new SnapshotParameters(); parameter.setViewport(viewPort); parameter.setFill(Color.TRANSPARENT); return croppedImageView.snapshot(parameter, null); }
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 . j a v a 2 s . c o m 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; }
From source file:com.chart.SwingChart.java
/** * Copy to clipboard/*from w ww .j av a 2 s. c o m*/ * @param node JavaFX Node to copy */ public final void copyClipboard(final Node node) { WritableImage captura = node.snapshot(new SnapshotParameters(), null); ImageView iv = new ImageView(captura); Clipboard clipboard = Clipboard.getSystemClipboard(); ClipboardContent content = new ClipboardContent(); content.put(DataFormat.IMAGE, captura); clipboard.setContent(content); }
From source file:eu.mihosoft.vrl.fxscad.MainController.java
@FXML private void onExportAsPngFile(ActionEvent e) { if (csgObject == null) { Action response = Dialogs.create().title("Error").message("Cannot export PNG. There is no geometry :(") .lightweight().showError(); return;//from w w w.j a va 2s . c o m } FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Export PNG File"); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Image files (*.png)", "*.png")); File f = fileChooser.showSaveDialog(null); if (f == null) { return; } String fName = f.getAbsolutePath(); if (!fName.toLowerCase().endsWith(".png")) { fName += ".png"; } int snWidth = 1024; int snHeight = 1024; double realWidth = viewGroup.getBoundsInLocal().getWidth(); double realHeight = viewGroup.getBoundsInLocal().getHeight(); double scaleX = snWidth / realWidth; double scaleY = snHeight / realHeight; double scale = Math.min(scaleX, scaleY); PerspectiveCamera snCam = new PerspectiveCamera(false); snCam.setTranslateZ(-200); SnapshotParameters snapshotParameters = new SnapshotParameters(); snapshotParameters.setTransform(new Scale(scale, scale)); snapshotParameters.setCamera(snCam); snapshotParameters.setDepthBuffer(true); snapshotParameters.setFill(Color.TRANSPARENT); WritableImage snapshot = new WritableImage(snWidth, (int) (realHeight * scale)); viewGroup.snapshot(snapshotParameters, snapshot); try { ImageIO.write(SwingFXUtils.fromFXImage(snapshot, null), "png", new File(fName)); } catch (IOException ex) { Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:be.makercafe.apps.makerbench.editors.JFXMillEditor.java
private void handleExportAsPngFile(ActionEvent e) { if (millObject == null) { Alert alert = new Alert(AlertType.ERROR); alert.setTitle("Oeps an error occured"); alert.setHeaderText("Cannot export PNG. There is no geometry !"); alert.setContentText("Please verify that your code generates a valid CSG object."); alert.showAndWait();//from w ww.ja va 2 s . c o m return; } FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Export PNG File"); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Image files (*.png)", "*.png")); File f = fileChooser.showSaveDialog(null); if (f == null) { return; } String fName = f.getAbsolutePath(); if (!fName.toLowerCase().endsWith(".png")) { fName += ".png"; } int snWidth = 1024; int snHeight = 1024; double realWidth = viewGroup.getBoundsInLocal().getWidth(); double realHeight = viewGroup.getBoundsInLocal().getHeight(); double scaleX = snWidth / realWidth; double scaleY = snHeight / realHeight; double scale = Math.min(scaleX, scaleY); PerspectiveCamera snCam = new PerspectiveCamera(false); snCam.setTranslateZ(-200); SnapshotParameters snapshotParameters = new SnapshotParameters(); snapshotParameters.setTransform(new Scale(scale, scale)); snapshotParameters.setCamera(snCam); snapshotParameters.setDepthBuffer(true); snapshotParameters.setFill(Color.TRANSPARENT); WritableImage snapshot = new WritableImage(snWidth, (int) (realHeight * scale)); viewGroup.snapshot(snapshotParameters, snapshot); try { ImageIO.write(SwingFXUtils.fromFXImage(snapshot, null), "png", new File(fName)); } catch (IOException ex) { Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex); Alert alert = new Alert(AlertType.ERROR); alert.setTitle("Oeps an error occured"); alert.setHeaderText("Cannot export PNG. There went something wrong writing the file."); alert.setContentText( "Please verify that your file is not read only, is not locked by other user or program, you have enough diskspace."); alert.showAndWait(); } }
From source file:be.makercafe.apps.makerbench.editors.GCodeEditor.java
private void handleExportAsPngFile(ActionEvent e) { if (csgObject == null) { Alert alert = new Alert(AlertType.ERROR); alert.setTitle("Oeps an error occured"); alert.setHeaderText("Cannot export PNG. There is no geometry !"); alert.setContentText("Please verify that your code generates a valid CSG object."); alert.showAndWait();/*from w w w . ja va 2 s . com*/ return; } FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Export PNG File"); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Image files (*.png)", "*.png")); File f = fileChooser.showSaveDialog(null); if (f == null) { return; } String fName = f.getAbsolutePath(); if (!fName.toLowerCase().endsWith(".png")) { fName += ".png"; } int snWidth = 1024; int snHeight = 1024; double realWidth = viewGroup.getBoundsInLocal().getWidth(); double realHeight = viewGroup.getBoundsInLocal().getHeight(); double scaleX = snWidth / realWidth; double scaleY = snHeight / realHeight; double scale = Math.min(scaleX, scaleY); PerspectiveCamera snCam = new PerspectiveCamera(false); snCam.setTranslateZ(-200); SnapshotParameters snapshotParameters = new SnapshotParameters(); snapshotParameters.setTransform(new Scale(scale, scale)); snapshotParameters.setCamera(snCam); snapshotParameters.setDepthBuffer(true); snapshotParameters.setFill(Color.TRANSPARENT); WritableImage snapshot = new WritableImage(snWidth, (int) (realHeight * scale)); viewGroup.snapshot(snapshotParameters, snapshot); try { ImageIO.write(SwingFXUtils.fromFXImage(snapshot, null), "png", new File(fName)); } catch (IOException ex) { Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex); Alert alert = new Alert(AlertType.ERROR); alert.setTitle("Oeps an error occured"); alert.setHeaderText("Cannot export PNG. There went something wrong writing the file."); alert.setContentText( "Please verify that your file is not read only, is not locked by other user or program, you have enough diskspace."); alert.showAndWait(); } }