How to take snapshot From node which is not on the scene

ぐ巨炮叔叔 提交于 2019-11-30 19:48:37

Accoring to documentation of Node.snapshot

NOTE: In order for CSS and layout to function correctly, the node must be part of a Scene (the Scene may be attached to a Stage, but need not be).

You can create new Scene without attaching it to Stage and even without displaying it:

WritableImage writableImage = new WritableImage(1000, 600);

// here is your node such as PointLight
new Circle(200, 200, 50).snapshot(null, writableImage);

new Scene(chartVH, 1000, 600);
chartVH.snapshot(null, writableImage);
File outFile = new File("/tmp/aa.png");
System.out.println(outFile);
try {
    ImageIO.write(SwingFXUtils.fromFXImage(writableImage, null), "png", outFile);
} catch (IOException e) {
    e.printStackTrace();
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!