Checking is a pixel transparent or not??

Hello I need to know a pixel is transparent or not.
I convert a color of an image to transparent with this function :


BufferedImage image;
int x, y;

int col = image.getRGB(x, y);
image.setRGB(x, y, col & 0x00ffffff);

The color of the image in coordinate x, y is converted to transparent.

Now i need to check whether the color is transparent or not :


BufferedImage image;
int x, y;

int col = image.getRGB(x, y);

if (col == ????) {
   System.out.println("transparent color");
} else {
   System.out.println("opaque color");
}

Anyone know about this?

What I’m confuse is the transparent color of a new created blank image (GraphicsConfiguration.createCompatibleImage(width, height, Transparency.BITMASK)) is 0, but when I use above code to convert a color to transparent, the transparent color is not 0???

Thanks

To solve your testing problem, you can use a bitwise operation:

if((col & 0xFF000000) == 0x00) 
{ 
    System.out.println("transparent color"); 
} 
else 
{ 
    System.out.println("opaque color"); 
}

Checking for partial transparency can be done with:

if((col & 0xFF000000) != 0xFF000000)

Any questions?

Edit: Took me a few tries to get the code right. :wink:

Wow thanks a million jbanes!!!
Now my pixel perfect collision working perfectly!! Wohoo!! ;D
Thanks thanks thanks :wink: