Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

javafx-8

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?

like image 724
Eeliya Avatar asked May 11 '14 09:05

Eeliya


1 Answers

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();
}
like image 178
ruX Avatar answered Nov 17 '22 05:11

ruX