Return to Snippet

Revision: 44963
at April 21, 2011 08:58 by mouseroot


Initial Code
public Image makeColorTrans(Image im,final Color c)
    {
        ImageFilter filter = new RGBImageFilter()
        {
      // the color we are looking for... Alpha bits are set to opaque
      public int markerRGB = c.getRGB() | 0xFF000000;

      public final int filterRGB(int x, int y, int rgb) {
        if ( ( rgb | 0xFF000000 ) == markerRGB ) {
          // Mark the alpha bits as zero - transparent
          return 0x00FFFFFF & rgb;
          }
        else {
          // nothing to do
          return rgb;
          }
        }
      };

    ImageProducer ip = new FilteredImageSource(im.getSource(), filter);
    return Toolkit.getDefaultToolkit().createImage(ip);
    }

Initial URL

                                

Initial Description
nifty little function when you want transparent images such as sprite sheets

Initial Title
Set Image Color as Transparent

Initial Tags

                                

Initial Language
Java