Alpha Filter

Java 1.1

I’m trying to make a spirte that fades out to completely transparent using java.awt.image.ImageFilter class.

I want to make this Java 1.1 compatible since the rest of my game is.

So far, I’ve been able to create an image that fades out, but I’m having trouble getting the background to stay transparent.

I’m using a GIF with transparent background, but I only want the spirte image itself to fade. Right now, when I put the image through the filter, the transparent background is showing as a translucent white.

Any thoughts on the best way to handle this?

Is there a way to specify that a certain color (white) will always be completely transparent?

Thanks,

Drew

It’d be easier if you post some code from your filter…

here is the complete answer to your question:

NOTE: I wrote this code based on a similar function found at www.rgagnon.com, check them out they have a lot of useful source code

public Image makeAColorTransparent(Image image, final Color tColor){
ImageFilter filter = new RGBImageFilter(){
public final int filterRGB(int x, int y, int rgb){
if(rgb == tColor.getRGB()){
return 0x00FFFFFF & rgb;
}
else return rgb;
}
};
ImageProducer iProducer = new FilterImageSource(image.getSource(), filter);
return Toolkit.getDefaultToolkit().createImage(iProducer);
}