copy the contents of an image

Hi!

I need to copy the contents of an image (bufferedimage or volatileimage) unto another for backup purposes. Is it enough to do a simple variable assignation like this ?

Image im1;
Image im2;

im1=im2;

thanks in advance

No, that will only copy the reference to the image.

you could do something like this to achive the copying.


img2=  GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(img1.getWidth(null),img1.getHeight(null), Transparency.BITMASK);
Graphics2D g2d = img2.createGraphics();
g2d.drawImage(img1,0,0,null);
g2d.dispose();

Don’t forget the :-

g2d.setComposite(AlphaComposite.SRC);

to ensure any alpha values are maintained.

Thanks, it works. ;D