Java Code Examples for javafx.scene.SnapshotParameters#setTransform()
The following examples show how to use
javafx.scene.SnapshotParameters#setTransform() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FxmlControl.java From MyBox with Apache License 2.0 | 6 votes |
public static Image snap(Node node) { try { final Bounds bounds = node.getLayoutBounds(); double scale = dpiScale(); int imageWidth = (int) Math.round(bounds.getWidth() * scale); int imageHeight = (int) Math.round(bounds.getHeight() * scale); final SnapshotParameters snapPara = new SnapshotParameters(); snapPara.setFill(Color.TRANSPARENT); snapPara.setTransform(javafx.scene.transform.Transform.scale(scale, scale)); WritableImage snapshot = new WritableImage(imageWidth, imageHeight); snapshot = node.snapshot(snapPara, snapshot); return snapshot; } catch (Exception e) { logger.debug(e.toString()); return null; } }
Example 2
Source File: SVGDocumentGenerator.java From latexdraw with GNU General Public License v3.0 | 6 votes |
/** * Creates a thumbnail from the given selection in the given file. * @param templateFile The file of the future thumbnail. * @param selection The set of shapes composing the template. */ private void createTemplateThumbnail(final File templateFile, final javafx.scene.Group selection) { final Bounds bounds = selection.getBoundsInParent(); final double scale = 70d / Math.max(bounds.getWidth(), bounds.getHeight()); final WritableImage img = new WritableImage((int) (bounds.getWidth() * scale), (int) (bounds.getHeight() * scale)); final SnapshotParameters snapshotParameters = new SnapshotParameters(); snapshotParameters.setFill(Color.WHITE); snapshotParameters.setTransform(new Scale(scale, scale)); selection.snapshot(snapshotParameters, img); final BufferedImage bufferedImage = SwingFXUtils.fromFXImage(img, null); try { ImageIO.write(bufferedImage, "png", templateFile); //NON-NLS }catch(final IOException ex) { BadaboomCollector.INSTANCE.add(ex); } bufferedImage.flush(); }
Example 3
Source File: Export.java From latexdraw with GNU General Public License v3.0 | 5 votes |
/** * @return A writable image that contains given views (not null). */ private @NotNull BufferedImage createRenderedImage() { final Group views = canvas.getViews(); final Bounds bounds = views.getBoundsInParent(); final double scale = 3d; final WritableImage img = new WritableImage((int) (bounds.getWidth() * scale), (int) (bounds.getHeight() * scale)); final SnapshotParameters snapshotParameters = new SnapshotParameters(); snapshotParameters.setFill(Color.WHITE); snapshotParameters.setTransform(new Scale(scale, scale)); views.snapshot(snapshotParameters, img); return SwingFXUtils.fromFXImage(img, null); }
Example 4
Source File: ImageManufactureRichTextController.java From MyBox with Apache License 2.0 | 4 votes |
protected void makeImage() { try { if (webView == null || webEngine == null || !webView.isVisible()) { return; } synchronized (this) { if (task != null) { return; } final double rotate = webView.getRotate(); webView.setRotate(0); // webEngine.executeScript("document.body.style.backgroundColor = '" // + FxmlColor.rgb2css((Color) bgRect.getFill()) + "'; opacity:" + opacity); // webView.setOpacity(1); // webEngine.executeScript("document.body.style.backgroundColor = 'rgba(0,0,0,0)';"); // http://news.kynosarges.org/2017/02/01/javafx-snapshot-scaling/ double scale = FxmlControl.dpiScale(); final WritableImage snap = new WritableImage( (int) Math.round(webView.getWidth() * scale), (int) Math.round(webView.getHeight() * scale)); final SnapshotParameters parameters = new SnapshotParameters(); parameters.setTransform(Transform.scale(scale, scale)); parameters.setFill(Color.TRANSPARENT); webView.snapshot(parameters, snap); if (!parent.editable.get()) { return; } task = new SingletonTask<Void>() { private Image transparent, blended; @Override protected boolean handle() { try { transparent = FxmlImageManufacture.replaceColor(snap, Color.WHITE, Color.TRANSPARENT, 0); blended = FxmlImageManufacture.drawHTML(imageController.imageView.getImage(), transparent, imageController.maskRectangleData, (Color) bgRect.getFill(), opacity, arc, (int) rotate, marginsWidth); if (task == null || isCancelled()) { return false; } return blended != null; } catch (Exception e) { logger.error(e.toString()); return false; } } @Override protected void whenSucceeded() { if (isPreview) { webView.setRotate(rotate); // ImageViewerController controller1 // = (ImageViewerController) openStage(CommonValues.ImageFxml); // controller1.loadImage(transparent); ImageViewerController controller = (ImageViewerController) openStage(CommonValues.ImageViewerFxml); controller.loadImage(blended); controller.setAsPopped(); } else { parent.updateImage(ImageOperation.RichText, null, null, blended, cost); webView = null; } } }; parent.openHandlingStage(task, Modality.WINDOW_MODAL); Thread thread = new Thread(task); thread.setDaemon(true); thread.start(); } } catch (Exception e) { logger.error(e.toString()); } }