I have a method to determine a color based on some value. The method is as such:
public Color color(double val) {
double H = val * 0.3;
double S = 0.9;
double B = 0.9;
return Color.getHSBColor((float)H, (float)S, (float)B);
}
I also want to make the color created trasparent. How can I do this? Thanks
The easiest way is to specify R, G, B, and A directly, using this constructor:
public Color(float r, float g, float b, float a)
.
I know you have HSB, but you can convert to RGB easily enough.
I know this is old, but all I do when I want opacity made with the Java built-in Graphics Object, is new Color(RRR, GGG, BBB, AAA)
.
Used in context:
g.setColor(new Color(255, 255, 255, 80));
Last value is alpha channel/opacity, higher number means more opaque.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With