How can I use the HSL colorspace in Java?

前端 未结 6 1071
遇见更好的自我
遇见更好的自我 2021-02-12 22:51

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 const

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-12 23:22

    Most of the given answers here seem to assume that HSL == HSB, which is false. The HSB colorspace is useful (and used) in many cases, but there is one notable exception: CSS. The non-RGB css color functions, hsl() and hsla() are HSL, not HSB. As such, it is very useful to be able to convert to and from HSL in java.

    There is a good writeup about the problem here: http://tips4java.wordpress.com/2009/07/05/hsl-color/ TL;DR: the code is here: http://www.camick.com/java/source/HSLColor.java

    The methods therein are pretty easy to extract if you don't want to use the whole class.

    It doesn't appear that the author of the class included a license, though the context of the blog post seems to imply public domain. Use your own judgement.

提交回复
热议问题