3

我还没有找到可以转换rgb(0, 96, 255)为 HSL 并返回的算法/实现,而最终值不会略有不同(rgb(0, 98, 255))。这意味着每个人的算法都被破坏了(包括 Wolfram|Alpha)——或者 HSL 不能代表每种 RGB 颜色。

哪个是对的?

4

1 回答 1

1

n.m. is correct—"HSL can represent every RGB color, but HSL rounded to nearest integer cannot."

What I ended up doing with the color class I was writing was to internally store the color as unrounded HSL. Then the getter methods for RGB and HSL just rounded them when called. This enabled doing things like changing hue and saturation, even on RGB colors, without getting an inaccurate conversion.

There's still no way to accurately convert rounded RGB and rounded HSL, so the solution is to simply never convert rounded RGB to/from rounded HSL.

于 2012-07-20T01:21:33.853 回答