C# has a very convenient getHue method, but I can't find a setHue method. Is there one?
If not, I think the best way to define a color after changing the hue would be to convert the HSL value to RGB, and then set the RGB value. I know there are formulas on the internet for doing this, but how would I best go about performing this conversion from HSL to RGB using C#?
Thank You
System.Drawing.Color
is a value type, which are almost always made immutable, especially in frameworks. That's why you can'tsetHue
on it, you can only construct a new value type with fields you need.So, if you have a function that will give you RGB values for your HSB values, you can do it like this
where
FromHSB
looks like thisTo set the Hue you create a new
Color
, maybe from a given one by usingGetHue
andGetSaturation
. See below for thegetBrightness
function!I'm using this:
Do not use the built-in
GetBrightness
method! It returns the same value (0.5f) for red, magenta, cyan, blue and yellow (!). This is better: