Quantcast
Channel: User David Z - Stack Overflow
Viewing all articles
Browse latest Browse all 50

Answer by David Z for Java color opacity

$
0
0

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 50


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>