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