views:

207

answers:

3

I've had a look at the ColorSpace class, and found the constant TYPE_HLS (which presumably is just HSL in a different order).

Can I use this constant to create a Color from hue, saturation, and luminosity? If not, are there any Java classes for this, or do I need to write my own?

A: 

Maybe this will help. The JDK doesn't seem to be very helpful when wanting to use colors in another color space.

Edit: In ColorSpace.getName(idx) there's this little snippet:

 case ColorSpace.TYPE_HLS:
                    compName = new String[] {"Hue", "Lightness", 
                                             "Saturation"};

so it was what you thought, but looking at the type hierarchy of ColorSpace it doesn't seem to be used or implemented in any way anywhere. ColorSpace is extended by only two other classes BogusColorSpace and ICC_ColorSpace, so I'm guessing they're expecting developers to create their own implementations for different color spaces.

Andrei Fierbinteanu
A: 

Found it:

Color.getHSBColor(float h, float s, float l)
Eric
Well, HSB is not exactly the same as HSL.
Andrei Fierbinteanu
e.g. `Color.getHSBColor(0, 1, 1)` would return the color red, but if you wanted the color for (H=0, S=1, L=1) you should get white.
Andrei Fierbinteanu
@Andrei: Indeed. http://en.wikipedia.org/wiki/HSL_and_HSV: "HSV stands for hue, saturation, and value, and is also often called HSB (B for brightness)."
JAB
+2  A: 

I don't think there is any need to use ColorSpaces here. Try something like the following:

float hue = 0.9f; //hue
float lumination= 0.8f; //lumination
float saturation = 1.0f; //saturation

Color myRGBColor = Color.getHSBColor(hue, saturation, lumination);
Segphault
Gah, apparently I was too slow -- it seems you already figured this out.
Segphault
You can have an upvote anyway
Eric
Note that the B is actually "brightness", not luminosity/lightness, and is another term for the "value" attribute of the HSV color space.
JAB