是这种情况:
我在窗格中添加了Mesh和PointLight,我想从窗格中拍摄快照并在图像视图中显示结果.但这仅在将窗格添加到场景中时有效.
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?
推荐答案根据 Node.snapshot
注意:为了使CSS和布局正确运行,该节点必须是Scene的一部分(该Scene可以附加到Stage上,但不一定要附加到此舞台上.)
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(); }更多推荐
如何从不在现场的节点拍摄快照
发布评论