Building a buffered image with transparency?
Hi all,
I am wondering if there is a way to paste a transparent image (gif) into a constructed Image without losing its transparency.
I came across it as I was trying to build a new Image by pasting a number of transparent images into a 'buffer' image. Up to now, the buffer worked fine, except that it lost all transparency.
Consider the example below.
class myclass extends Component{
public myclass( int w, int h){
Image originalgif= Toolkit.getDefaultToolkit().getImage("smiley.gif");
// make sure the image is loaded
try {
MediaTracker tracker = new MediaTracker(parent);
tracker.addImage(originalgif, 0);
tracker.waitForID(0);
} catch (InterruptedException iex) {
iex.printStackTrace();
}
// build a new image containing the transparent GIF
Image rescaledgif=new BufferedImage(w,h,BufferedImage.TYPE_3BYTE_BGR);
Graphics g=rescaledgif.getGraphics();
g.drawImage(originalgif, w,h, this);
}
public void Paint(Graphics g){
g.drawImage(originalgif,0,0,this);
// draws a transparent gif
g.drawImage(rescaledgif,100,100,this);
// draws the same gif rescaled no longer transparent but on a gray background
}
}
Is there a way to have the rescaled image still having its transparency? may be using a different colordepth for the buffered image, may be by defining a transparent color in the DrawImage() functions?
thanks in advance,
'Niklas

