Quantcast
Viewing all articles
Browse latest Browse all 49

Answer by David Z for Java color opacity

Use the Color constructor that takes a value with an alpha channel. Specifically, first you convert your color coordinates to RGB space:

int rgba = Color.HSBtoRGB(H, S, B);

and then add the desired amount of transparency,

rgba = (rgba & 0xffffff) | (alpha << 24);

where alpha is an integer between 0 (fully transparent) and 255 (fully opaque), inclusive. This value you can pass to the Color constructor, making sure to give true for the second argument.

Color c = new Color(rgba, true);

Viewing all articles
Browse latest Browse all 49

Trending Articles