[EMAIL PROTECTED] wrote:
I have a VolatileImage and I would like to take a snapshot of a region of it
and then restore this region at a later time. I cannot quite figure out how to
do it.
So far, I have established that I need to firstly get the snapshot using the
image.getSnapshot() method which creates a BufferedImage of the entire volatile
image. Then it would seem I need to use the copy the bufferedImage.copyData()
method to copy the region I want but that method requires a Raster. So first I
have to create Raster. To do this I think I should use the
Raster.createWritableRaster() method which requires a SampleModel and a Point.
To create the SampleModel it looks like I should be using a
SinglePixelPackedSampleModel. To create the SinglePixelPackedSampleModel I
need to specify an array of bit masks.
What do I need to put into this bit mask array? Or, is there a simple way of
doing this? It seems rather complicated! Perhaps someone has an example of
this kind of thing?
I'm not quite sure what you're trying to do. If you already
have a BufferedImage with VolatileImage's contents, isn't
that enough?
If you only need to save a part of VolatileImage, you
can just copy part of VI to another image.
You can create an image with the same ColorModel as the VI
using GraphicsConfiguration.createCompatibleImage(w,h)
where GraphicConfiguration is the same that the original
VolatileImage was created from so that both images have
the same format and you don't lose precision (if it was
created using Component.createVolatileImage(), then it's
the GC of the Component).
So:
Image save = gc.createCompatibleImage(saveW, saveH);
// validate the volatile image
do {
vi.validate(gc);
// handle vi validation
Graphics g = save.getGraphics();
g.drawImage(vi, 0, 0, saveW, saveH, srcX, srcY, srcX+saveW, srcY+saveH,
null);
} while (vi.contentsLost());
Now you have part of IV in "save". To restore it,
just drawImage it to the VI.
If you needed direct pixel access to the pixels of the saved image,
you can create a BufferedImage of the desired format
('new BufferedImage(saveW, saveH, BufferedImage.TYPE_INT_RGB)', for example)
Thanks,
Dmitri
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".