Converting from HSV (HSB in Java) to RGB without u

2020-02-04 20:36发布

I figured I should post this question, even if I have already found a solution, as a Java implementation was not readily available when I searched for it.

Using HSV instead of RGB allows the generation of colors with the same saturation and brightness (something I wanted).

Google App Engine does not allow use of java.awt.Color, so doing the following to convert between HSV and RGB is not an option:

Color c = Color.getHSBColor(hue, saturation, value);
String rgb = Integer.toHexString(c.getRGB());

Edit: I moved my answer as described in the comment by Nick Johnson.

Ex animo, - Alexander.

7条回答
ゆ 、 Hurt°
2楼-- · 2020-02-04 21:09

You should use the HSBtoRGB implementation provided by Oracle, copying its source code into your project. java.awt.Color is open-source. The algorithms provided by Peter Recore and Yngling are not robust and will return illegal RGB values like "256,256,0" for certain inputs. Oracle's implementation is robust, use it instead.

查看更多
登录 后发表回答