java - 将 AnchorPane 打印为 PNG

标签 java javafx png

我会将我的锚定 Pane 打印为 png:我在我的 Controller 中加载了一个图像并写了一些文本,而不是我想保存整个面板,但我不知道我必须使用哪些工具。

URL fxmlpath = this.getClass().getResource("/fxml/ListaNotaSpesa.fxml");

FXMLLoader loader = new FXMLLoader();
AnchorPane pane= loader.load(fxmlpath);


Scene scene = new Scene(pane);

primaryStage.setTitle("Inserisci Note Spese");
primaryStage.setScene(scene);
primaryStage.show();

最佳答案

您可以使用 Node.snapshot .

Takes a snapshot of this node at the next frame and calls the specified callback method when the image is ready. CSS and layout processing will be done for the node, and any of its children, prior to rendering it. The entire destination image is cleared to the fill Paint specified by the SnapshotParameters. This node is then rendered to the image.

例子:

WritableImage image = anchorPane.snapshot(new SnapshotParameters(), null);

File file = new File("D:\\anchor.png");

ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file);

关于java - 将 AnchorPane 打印为 PNG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41933192/

相关文章:

Java 1.8 递归 lambda

image - 在 javafx 中创建图像覆盖掩码

css - JavaFX 样式化相同类型的所有节点,例如 VBox

c++ - Visual C++ 如何使用 CPaintDC、CDC 在 CView 中重绘图像

java - lambda 表达式和全局变量

java - slf4j没用吗?

javascript - snap.svg 将 svg 保存为 png

image - 将 base64 图像字符串转换为可以使用 node.js 提供给浏览器的图像文件

java - 如何编写适合所需模式而不适合其他模式的正则表达式?

按钮的 Javafx 背景图像不起作用