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

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

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

Node.snapshot介绍

暂无

代码示例

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

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

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

public static BufferedImage generate_png_from_container(Node node) {
    SnapshotParameters param = new SnapshotParameters();
    param.setDepthBuffer(true);
    WritableImage snapshot = node.snapshot(param, null);
    BufferedImage tempImg = SwingFXUtils.fromFXImage(snapshot, null);
    BufferedImage img = null;
    byte[] imageInByte;
    try {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ImageIO.write(tempImg, "png", baos);
      baos.flush();
      imageInByte = baos.toByteArray();
      baos.close();
      InputStream in = new ByteArrayInputStream(imageInByte);
      img = ImageIO.read(in);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    //the final image sent to the PDJpeg
    return img;
}

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

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

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

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

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

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

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

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

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

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

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

/**
 * save a snapshot of the given node as a PNG file
 * @param node - the node to get a snapshot from
 * @param file - the file to save to
 */
public static synchronized void saveAsPng(Node node, File file) {
  Bounds bounds = node.getBoundsInParent();
  WritableImage writableImage = new WritableImage((int) bounds.getWidth(), (int) bounds.getHeight());
  SnapshotParameters params = new SnapshotParameters();
  node.snapshot(params, writableImage);
  try {
    ImageIO.write(fromFXImage(writableImage, null), "png", file);
  } catch (Throwable th) {
    ErrorHandler.handle(th);
  }
}

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

private EventHandler<? super MouseEvent> onDragDetected() {
  return evt -> {
    Node node = (Node) evt.getSource();
    Dragboard db = node.startDragAndDrop(TransferMode.MOVE);
    db.setDragView(createSnapshot(node), evt.getX(), evt.getY());

    ClipboardContent content = new ClipboardContent();
    content.putString("");
    db.setContent(content);

    evt.consume();
  };
}

private WritableImage createSnapshot(Node node) {
  SnapshotParameters snapshotParams = new SnapshotParameters();
  WritableImage image = node.snapshot(snapshotParams, null);
  return image;
}

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

public Node createReplacement(Node node)
{
  Rectangle2D b = getBounds(node);
  Node replNode = new ImageView(node.snapshot(new SnapshotParameters(), null));
  replacedNodeMap.put(node, replNode);
  replNode.setUserData(node);
  replNode.setManaged(false);
  replNode.setId(ANIM_REPLACE_ID);
  replNode.resizeRelocate(b.getMinX(), b.getMinY(), b.getWidth(), b.getHeight());
  return replNode;
}

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

node.snapshot(parameters, wi);

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

node.snapshot(parameters, wi);

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

node.snapshot(parameters, wi);

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

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

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

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

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

/**
 * {@inheritDoc}
 */
@Override
protected void perform(Wave wave) throws CommandException {
  final SnapshotWaveBean wb = waveBean(wave);
  WritableImage image = wb.image();
  if (wb.node() == null) {
    final Scene scene = localFacade().globalFacade().application().scene();
    image = scene.snapshot(image);
  } else {
    image = wb.node().snapshot(wb.parameters(), image);
  }
  wb.image(image);
}

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

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

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

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

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

public static Group convertTo3D(Node node, int depth) {
  Group root = new Group();
  root.setTranslateX(node.getLayoutX());
  root.setTranslateY(node.getLayoutY());
  root.setTranslateZ(-20);
  System.out.println("Layer " + depth + " - Node Type: " + node.getClass());
  Box box = new Box(node.getBoundsInParent().getWidth(), node.getBoundsInParent().getHeight(), 0.1);
  box.setTranslateX(node.getLayoutX());
  box.setTranslateY(node.getLayoutY());
  SnapshotParameters snapshotParameters = new SnapshotParameters();
  snapshotParameters.setFill(Color.TRANSPARENT);
  box.setMaterial(new PhongMaterial(Color.WHITE, node.snapshot(snapshotParameters, new WritableImage((int) node.getBoundsInParent().getWidth(), (int) node.getBoundsInParent().getHeight())), null, null, null));
  root.getChildren().add(box);
  if (node instanceof Parent) {
    for (Node child : ((Parent) node).getChildrenUnmodifiable()) {
      root.getChildren().add(convertTo3D(child, depth + 1));
    }
  }
  return root;
}

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

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

相关文章

微信公众号

最新文章

更多

Node类方法