将 AnchorPane 打印为 PNG
Print AnchorPane as PNG
我会将我的锚窗格打印为 png:我在我的控制器中加载了一个图像并写了一些文本,而不是我想保存整个面板,但我不知道我必须使用哪些工具。
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);
我会将我的锚窗格打印为 png:我在我的控制器中加载了一个图像并写了一些文本,而不是我想保存整个面板,但我不知道我必须使用哪些工具。
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);