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?
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With