问题
As I understand it HSL and HSB colour spaces are very similar, both use the same 0-360 colour wheel for hue and the same 0-1 value for saturation. The one difference between them is that in the HSB model you have brightness, where 0 is black and 1 is the colour at full intensity, while in HSL you have lightness/luminosity, where 0 is still black but 1 is white.
The .net Color
struct uses the RGB space, but has GetHue()
, GetSaturation()
and GetBrightness()
functions.
The documentation here is confusing. For GetBrightness()
:
/// <summary>Gets the hue-saturation-brightness (HSB) brightness value for this
/// System.Drawing.Color structure.</summary>
Ok, so makes sense, .Net appears to be using HSB...
/// <returns>The brightness of this System.Drawing.Color. The brightness ranges
/// from 0.0 through 1.0, where 0.0 represents black and 1.0 represents white.
/// </returns>
Er... so the max value represents white, rather than the brightest colour. Despite the fact that their documents and naming consistently refers to brightness I'm pretty sure that the value returned is actually lightness/luminosity, i.e. .Net actually uses the HSL model and not HSB.
Can anyone confirm this? Is it an error in the documentation, an error in GetBrightness()
, or am I misunderstanding the theory somehow?
回答1:
The page you linked to gives examples of L and V (aka B) for a range of colours. Comparing the result of Color.FromArgb(255, 255, 0, 0).GetBrightness
(0.5) to the examples shows that .NET is using the HSL model. A check of Color.FromArgb(255, 128, 255, 255).GetSaturation
(1.0) confirms it.
Others have discovered the same thing, e.g. Chris Jackson (MSFT) in Converting from HSB to RGB in .NET: "The underlying issue is that the .NET Framework refers to the color space as HSB even though it actually is HSL. (The color picker control refers to it correctly.) The Color structure in the framework provides a GetBrightness() method, described in the documentation as, "Gets the hue-saturation-brightness (HSB) brightness value for this Color structure." Is this wrong? You bet. It should be called GetLuminance()."
来源:https://stackoverflow.com/questions/24732836/does-the-net-color-struct-use-an-hsb-or-hsl-colour-space