javafx.scene.Node.snapshot()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(290)

本文整理了Java中javafx.scene.Node.snapshot()方法的一些代码示例,展示了Node.snapshot()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.snapshot()方法的具体详情如下:
包路径:javafx.scene.Node
类名称:Node
方法名:snapshot

Node.snapshot介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

  1. dragImageView.setImage(node.snapshot(snapParams, null));

代码示例来源:origin: stackoverflow.com

  1. public static BufferedImage generate_png_from_container(Node node) {
  2. SnapshotParameters param = new SnapshotParameters();
  3. param.setDepthBuffer(true);
  4. WritableImage snapshot = node.snapshot(param, null);
  5. BufferedImage tempImg = SwingFXUtils.fromFXImage(snapshot, null);
  6. BufferedImage img = null;
  7. byte[] imageInByte;
  8. try {
  9. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  10. ImageIO.write(tempImg, "png", baos);
  11. baos.flush();
  12. imageInByte = baos.toByteArray();
  13. baos.close();
  14. InputStream in = new ByteArrayInputStream(imageInByte);
  15. img = ImageIO.read(in);
  16. } catch (IOException e) {
  17. // TODO Auto-generated catch block
  18. e.printStackTrace();
  19. }
  20. //the final image sent to the PDJpeg
  21. return img;
  22. }

代码示例来源:origin: org.controlsfx/controlsfx

  1. /**
  2. * Creates a snapshot of the node with the specified parameters.
  3. *
  4. * @param parameters
  5. * the {@link SnapshotParameters} used for the snapshot (must not be {@code null}); the viewport will be
  6. * interpreted relative to this control (like the {@link #selectionProperty() selection})
  7. * @return the {@link WritableImage} that holds the rendered viewport
  8. * @throws IllegalStateException
  9. * if {@link #nodeProperty() node} is {@code null}
  10. * @see Node#snapshot
  11. */
  12. public WritableImage createSnapshot(SnapshotParameters parameters) throws IllegalStateException {
  13. // make sure the node and the snapshot parameters exist
  14. Objects.requireNonNull(parameters, "The argument 'parameters' must not be null."); //$NON-NLS-1$
  15. if (getNode() == null) {
  16. throw new IllegalStateException("No snapshot can be created if the node is null (check 'getNode()')."); //$NON-NLS-1$
  17. }
  18. // take the snapshot
  19. return getNode().snapshot(parameters, null);
  20. }

代码示例来源:origin: stackoverflow.com

  1. Node backgroundNode = getBackgroundNode();
  2. backgroundNode.resize(1080, 720);
  3. backgroundNode.snapshot(new SnapshotParameters(), null);

代码示例来源:origin: stackoverflow.com

  1. WritableImage image = node.snapshot(new SnapshotParameters(), null);
  2. String base64String = encodeImageToString(SwingFXUtils.fromFXImage(image, null), "png");
  3. System.out.println("Base64 String : " + base64String);

代码示例来源:origin: stackoverflow.com

  1. Image chartSnapshot = node.snapshot(params, null);
  2. PngEncoderFX encoder = new PngEncoderFX(chartSnapshot, true);
  3. byte[] bytes = encoder.pngEncode();

代码示例来源:origin: stackoverflow.com

  1. Image fxImage = node.snapshot(null, null);
  2. BufferedImage bufferedImage = SwingFXUtils.fromFXImage(fxImage, null);

代码示例来源:origin: com.bitplan.gui/com.bitplan.javafx

  1. /**
  2. * save a snapshot of the given node as a PNG file
  3. * @param node - the node to get a snapshot from
  4. * @param file - the file to save to
  5. */
  6. public static synchronized void saveAsPng(Node node, File file) {
  7. Bounds bounds = node.getBoundsInParent();
  8. WritableImage writableImage = new WritableImage((int) bounds.getWidth(), (int) bounds.getHeight());
  9. SnapshotParameters params = new SnapshotParameters();
  10. node.snapshot(params, writableImage);
  11. try {
  12. ImageIO.write(fromFXImage(writableImage, null), "png", file);
  13. } catch (Throwable th) {
  14. ErrorHandler.handle(th);
  15. }
  16. }

代码示例来源:origin: stackoverflow.com

  1. private EventHandler<? super MouseEvent> onDragDetected() {
  2. return evt -> {
  3. Node node = (Node) evt.getSource();
  4. Dragboard db = node.startDragAndDrop(TransferMode.MOVE);
  5. db.setDragView(createSnapshot(node), evt.getX(), evt.getY());
  6. ClipboardContent content = new ClipboardContent();
  7. content.putString("");
  8. db.setContent(content);
  9. evt.consume();
  10. };
  11. }
  12. private WritableImage createSnapshot(Node node) {
  13. SnapshotParameters snapshotParams = new SnapshotParameters();
  14. WritableImage image = node.snapshot(snapshotParams, null);
  15. return image;
  16. }

代码示例来源:origin: com.miglayout/miglayout-javafx

  1. public Node createReplacement(Node node)
  2. {
  3. Rectangle2D b = getBounds(node);
  4. Node replNode = new ImageView(node.snapshot(new SnapshotParameters(), null));
  5. replacedNodeMap.put(node, replNode);
  6. replNode.setUserData(node);
  7. replNode.setManaged(false);
  8. replNode.setId(ANIM_REPLACE_ID);
  9. replNode.resizeRelocate(b.getMinX(), b.getMinY(), b.getWidth(), b.getHeight());
  10. return replNode;
  11. }

代码示例来源:origin: stackoverflow.com

  1. node.snapshot(parameters, wi);

代码示例来源:origin: stackoverflow.com

  1. node.snapshot(parameters, wi);

代码示例来源:origin: stackoverflow.com

  1. node.snapshot(parameters, wi);

代码示例来源:origin: ssaring/sportstracker

  1. /**
  2. * Prints the specified view node completely to one single page.
  3. *
  4. * @param printerJob printer job which defines the printer, page layout, ...
  5. * @param view view node to print
  6. * @return true when the view was printed successfully
  7. */
  8. private boolean printViewPage(final PrinterJob printerJob, final Node view) {
  9. // the view needs to be scaled to fit the selected page layout of the PrinterJob
  10. // => the passed view node can't be scaled, this would scale the displayed UI
  11. // => solution: create a snapshot image for printing and scale this image
  12. final WritableImage snapshot = view.snapshot(null, null);
  13. final ImageView ivSnapshot = new ImageView(snapshot);
  14. // compute the needed scaling (aspect ratio must be kept)
  15. final PageLayout pageLayout = printerJob.getJobSettings().getPageLayout();
  16. final double scaleX = pageLayout.getPrintableWidth() / ivSnapshot.getImage().getWidth();
  17. final double scaleY = pageLayout.getPrintableHeight() / ivSnapshot.getImage().getHeight();
  18. final double scale = Math.min(scaleX, scaleY);
  19. // scale the calendar image only when it's too big for the selected page
  20. if (scale < 1.0) {
  21. ivSnapshot.getTransforms().add(new Scale(scale, scale));
  22. }
  23. return printerJob.printPage(ivSnapshot);
  24. }

代码示例来源:origin: at.bestsolution.efxclipse.rt/org.eclipse.fx.ui.controls

  1. Dragboard db = node.startDragAndDrop(TransferMode.MOVE);
  2. WritableImage snapShot = node.snapshot(new SnapshotParameters(), null);
  3. PixelReader reader = snapShot.getPixelReader();
  4. int padX = 10;

代码示例来源:origin: org.jrebirth.af/component

  1. /**
  2. * {@inheritDoc}
  3. */
  4. @Override
  5. protected void perform(Wave wave) throws CommandException {
  6. final SnapshotWaveBean wb = waveBean(wave);
  7. WritableImage image = wb.image();
  8. if (wb.node() == null) {
  9. final Scene scene = localFacade().globalFacade().application().scene();
  10. image = scene.snapshot(image);
  11. } else {
  12. image = wb.node().snapshot(wb.parameters(), image);
  13. }
  14. wb.image(image);
  15. }

代码示例来源:origin: org.jrebirth/transition

  1. this.imageProperty.set(((ImageView) node).getImage());
  2. } else {
  3. final WritableImage wi = node.snapshot(new SnapshotParameters(), null);
  4. this.imageProperty.set(wi);

代码示例来源:origin: at.bestsolution.eclipse/org.eclipse.fx.ui.controls

  1. Dragboard db = node.startDragAndDrop(TransferMode.MOVE);
  2. WritableImage snapShot = node.snapshot(new SnapshotParameters(), null);
  3. PixelReader reader = snapShot.getPixelReader();
  4. int padX = 10;

代码示例来源:origin: com.guigarage/ui-basics

  1. public static Group convertTo3D(Node node, int depth) {
  2. Group root = new Group();
  3. root.setTranslateX(node.getLayoutX());
  4. root.setTranslateY(node.getLayoutY());
  5. root.setTranslateZ(-20);
  6. System.out.println("Layer " + depth + " - Node Type: " + node.getClass());
  7. Box box = new Box(node.getBoundsInParent().getWidth(), node.getBoundsInParent().getHeight(), 0.1);
  8. box.setTranslateX(node.getLayoutX());
  9. box.setTranslateY(node.getLayoutY());
  10. SnapshotParameters snapshotParameters = new SnapshotParameters();
  11. snapshotParameters.setFill(Color.TRANSPARENT);
  12. box.setMaterial(new PhongMaterial(Color.WHITE, node.snapshot(snapshotParameters, new WritableImage((int) node.getBoundsInParent().getWidth(), (int) node.getBoundsInParent().getHeight())), null, null, null));
  13. root.getChildren().add(box);
  14. if (node instanceof Parent) {
  15. for (Node child : ((Parent) node).getChildrenUnmodifiable()) {
  16. root.getChildren().add(convertTo3D(child, depth + 1));
  17. }
  18. }
  19. return root;
  20. }

代码示例来源:origin: at.bestsolution.efxclipse.rt/org.eclipse.fx.ui.controls

  1. final SnapshotParameters snapshotParameters = new SnapshotParameters();
  2. snapshotParameters.setFill(Color.TRANSPARENT);
  3. WritableImage snapShot = n.snapshot(snapshotParameters, null);
  4. ImageView v = new ImageView(snapShot);

相关文章

Node类方法