Masking PNG color

I want to load an image (.png) and mask it’s background color (0,247,0). None of the codes I found yet did work, does anyone have an idea?

okay, I found it out, if it can help someone…
One must iterate through all the pixels of the image and replace the pixels that have the color to mask like this:
pixel = pixel & 0x00ffffff

You can use ImageOps to do the job. Take a look at this tutorial:
http://java.sun.com/docs/books/tutorial/2d/images/filtering.html

In particular, this class may be interesting to you:
http://java.sun.com/j2se/1.4/docs/api/java/awt/image/ColorConvertOp.html

There’s an example of how to use these in the Java2Demo application shipped with the sdk.

Also, if the color you’re replacing is transparent (that is, alpha is x00), you can use Graphics.drawImage(image, w, h, Color) to replace it with provided color when you copy the image to the destination.

thanks for the reply :slight_smile: