如何从不在现场的节点拍摄快照 [英] How to take snapshot From node which is not on the scene

查看:68
本文介绍了如何从不在现场的节点拍摄快照的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是这种情况:

我在窗格中添加了MeshPointLight,我想从窗格中拍摄快照并在图像视图中显示结果.但这仅在将窗格添加到场景中时有效.

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?

推荐答案

根据

注意:为了使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();
}

这篇关于如何从不在现场的节点拍摄快照的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆