How to take a snapshot from a node that is not on the scene

In this case:

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

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

+7
source share
1 answer

Node.snapshot documentation confirmation

NOTE. For the CSS and layout to work correctly, the node must be part of the scene (the scene can be attached to the scene, but not necessarily).

You can create a new scene without tying it to Stage and not even 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(); } 
+6
source

All Articles