JavaFX:单个图像中的多个快照 [英] JavaFX: multiple snapshots in single image
问题描述
我学会了使用 snapshot
从节点中创建一个 Image
对象。有多个组
包含各种笔画,我现在尝试使用两组中的笔画创建一个图像。为此,我使用以下代码:
I learned to use snapshot
to make an Image
object out of a node. Having multiple Group
s that hold various strokes, I'm now trying to create a single Image with strokes from both groups. For this purpose I'm using the following code:
Group strokes1;
Group strokes2;
WriteableImage im = null;
SnapshotParameters params = new SnapshotParameters();
params.setFill(Color.TRANSPARENT);
params.setViewport(new Rectangle2D(0, 0, 400, 400));
im = strokes1.snapshot(params, im);
im = strokes2.snapshot(params, im);
snapshot
函数的文档说明
如果图像非空,则节点将渲染到现有图像中。
"If the image is non-null, the node will be rendered into the existing image."
但是,生成的图像 im
仅包含来自 strokes2 $ c $的笔画C>。我做错了什么?
However, the resulting Image im
only contains strokes from strokes2
. What am I doing wrong?
推荐答案
实现目标的一种方法是使用 setComposite()方法 Graphics2D //docs.oracle.com/javase/7/docs/api/java/awt/image/BufferedImage.htmlrel =nofollow noreferrer> BufferedImage 要转换,此解决方案将简要讨论此处和 here 。
One way to achieve your goal is to use setComposite() method on the Graphics2D of the BufferedImage to be converted, this solution is discussed briefly here and here.
这个 gist 提供了该方法的可运行完整示例。
this gist provide a runnable complete example of the approach.
这篇关于JavaFX:单个图像中的多个快照的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!