I’m trying to shift a portion of an image, currently using g.copyArea(). It works fine with solid colors, but the transparent pixels aren’t being copied (because they’re transparent!). I want to make the color underneath transparent.
This image shows what’s happening, if a start shape was copied, but I want the whole area to copy, overwriting the all pixels below.
alt text http://www.freeimagehosting.net/uploads/3f4b8888b0.png
This is what I want:
alt text http://www.freeimagehosting.net/uploads/ee911ea35a.png
BufferedImage b; ... Graphics g = b.getGraphics(); g.copyArea(x,y,w,h,dx,dy);
I have considered copying the image to another image, clearing the orginal image then copy it back to the new position, but there must be a better way?
Disclaimer: This is part of a homework project.
Use g.setComposite(AlphaComposite.Src), like so:
Thanks to unwind for suggesting the use of Graphics2D.