gpt4 book ai didi

java - 将 AnchorPane 打印为 PNG

转载 作者:行者123 更新时间:2023-11-30 10:33:56 24 4
gpt4 key购买 nike

我会将我的锚定 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com