【问题标题】:Print AnchorPane as PNG将 AnchorPane 打印为 PNG
【发布时间】:2017-06-15 10:48:07
【问题描述】:

我将我的锚窗格打印为 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();

【问题讨论】:

    标签: java javafx png


    【解决方案1】:

    您可以使用Node.snapshot

    在下一帧拍摄此节点的快照并调用 指定图像准备好时的回调方法。 CSS 和布局 将对节点及其任何子节点进行处理,先于 来渲染它。整个目标图像被清除填充 由 SnapshotParameters 指定的绘制。然后渲染这个节点 到图片。

    例子:

    WritableImage image = anchorPane.snapshot(new SnapshotParameters(), null);
    
    File file = new File("D:\\anchor.png");
    
    ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file);
    

    【讨论】:

    • 老兄,你救了我的工作
    猜你喜欢
    • 2020-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-25
    • 1970-01-01
    • 1970-01-01
    • 2013-07-01
    • 1970-01-01
    相关资源
    最近更新 更多