如何从不在现场的节点拍摄快照

编程入门 行业动态 更新时间:2024-10-26 19:31:44
本文介绍了如何从不在现场的节点拍摄快照的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是这种情况:

我在窗格中添加了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(); }

更多推荐

如何从不在现场的节点拍摄快照

本文发布于:2023-11-27 09:37:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637541.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:快照   节点   在现场

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!