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

吃可爱长大的小学妹 提交于 2019-11-30 04:44:02

问题


This is the case:

I have a Mesh and PointLight added to the pane and I want to take snapshot from pane and show the result in the image view. But it only works when I add the pane to the scene.

Is there any way to take snapshot from a node which has been not added to the scene?


回答1:


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();
}


来源:https://stackoverflow.com/questions/23590974/how-to-take-snapshot-from-node-which-is-not-on-the-scene

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!