Change Brightness via HSB

P

Petra Neumann

Hi,

I would like to change the brightness of a Color object in Java. To do
so I change the Color to the HSB color space, increase the brightness
and convert it back to RGB. However, the output color is NOT brighter,
it seems rather strange.

I have written the following code to do the conversion:

/////////////////
Color c = color.get(); (conversion from a Color3f - Java3D color)
System.out.println(c);

float[] hsb = Color.RGBtoHSB(c.getRed(),c.getGreen(),c.getBlue(),null);
hsb[2]=0.8f;

System.out.println(hsb[0]+" "+hsb[1]+" "+hsb[2]);

Color rgb = Color.getHSBColor(hsb[0],hsb[1],hsb[2]);
System.out.println(rgb);
/////////////////

This is an example output:
-----------------------------
java.awt.Color[r=95,g=28,b=0]
0.04912281 1.0 0.8
java.awt.Color[r=204,g=60,b=0]
------------------------------

The strange thing is that the "b" value always remains zero, but
shouldn't be because the original color should mereley becomes
brighter with a color close to white.

I appreciate any suggestions to solve my problem.
Thank you,

Cheers,
Petra
 
L

Liz

Petra Neumann said:
Hi,

I would like to change the brightness of a Color object in Java. To do
so I change the Color to the HSB color space, increase the brightness
and convert it back to RGB. However, the output color is NOT brighter,
it seems rather strange.

I have written the following code to do the conversion:

/////////////////
Color c = color.get(); (conversion from a Color3f - Java3D color)
System.out.println(c);

float[] hsb = Color.RGBtoHSB(c.getRed(),c.getGreen(),c.getBlue(),null);
hsb[2]=0.8f;

System.out.println(hsb[0]+" "+hsb[1]+" "+hsb[2]);

Color rgb = Color.getHSBColor(hsb[0],hsb[1],hsb[2]);
System.out.println(rgb);
/////////////////

This is an example output:
-----------------------------
java.awt.Color[r=95,g=28,b=0]
0.04912281 1.0 0.8
java.awt.Color[r=204,g=60,b=0]
------------------------------

The strange thing is that the "b" value always remains zero, but
shouldn't be because the original color should mereley becomes
brighter with a color close to white.

I appreciate any suggestions to solve my problem.
Thank you,

Cheers,
Petra

How about "public Color brighter()"
in java.awt.Color.java;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top