How to detect if a RGB is fully transparent?

Posted by omega on Stack Overflow See other posts from Stack Overflow or by omega
Published on 2014-08-23T04:15:23Z Indexed on 2014/08/23 4:20 UTC
Read the original article Hit count: 118

Filed under:
|

In java, I want to make a fully transparent RGBA, and I do that by using

public static int getTransparentRGB() {
    int r = 0;
    int g = 0;
    int b = 0;
    int a = 0;
    int new_pixel = (a << 24) | (r << 16) | (g << 8) | b;
    return new_pixel;
}

    Color color = new Color(getTransparentRGB());
    System.out.println(color.getAlpha()); // -> 255  ?!

I purposely keep all rgba values 0. However after I create the Color object with the rgba value as the constructor, if I call .getAlpha(), I get 255 even though I made the rgb value with a 0 alpha. If it returns 255, how could I tell the difference between a Color object that wasn't transparent, because that would also have a 255 alpha.

I expect the color object to return a 0 alpha based on the function above.

Does anyone know whats going on?

Thanks

© Stack Overflow or respective owner

Related posts about colors

Related posts about alpha