3

I learned to use snapshot to make an Image object out of a node. Having multiple Groups 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);

The documentation for the snapshot function says that

"If the image is non-null, the node will be rendered into the existing image."

However, the resulting Image im only contains strokes from strokes2. What am I doing wrong?

4

1 回答 1

2

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.

this gist provide a runnable complete example of the approach.

App snapshot

Image snapshot

于 2013-05-19T15:33:17.490 回答