On Thu, 23 Oct 2008 05:56:38 -0700, K Viltersten <tm**@viltersten.com>
wrote:
I've used the Colors class to access a bunch
of colors for my applications. Now, i'd like
to create a family for of each such color as
follows.
public Color Normal
{get{return Colors.Orange;}}
public Color Washed
{get{return Colors.Yellow;}}
public Color Satured
{get{return Colors.Red;}}
However, i don't really feel like setting up
a static map for each (most) of the colors.
I'd strongly prefer a facility that would
simply give me a washed and a saturated
version of whatever i put in.
Hints other than "write it yourself, you
lazy bum!", may i hope?
Unfortunately, as far as I know, neither .NET nor Windows provide built-in
conversion functions to go from HSV to RGB. The most natural way to
approach your problem would be to adjust the colors saturation in the HSV
color space and then generate an equivalent RGB value. (Oddly enough, you
_can_ go from RGB to HSV using the .NET Color structure, as it has
GetSaturation(), GetHue(), and GetBrightness() methods).
I find this especially odd, considering the built-in color picker dialog
does present the HSV model as an option.
If you want to write your own HSV to RGB function, you may find these
references useful:
http://www.cs.rit.edu/~ncs/color/t_convert.html http://blogs.msdn.com/cjacks/archive...12/575476.aspx http://splinter.com.au/blog/?p=29
Just take the color you want to saturate or desaturate, use the .NET
methods to get the HSV values, adjust the S component as desired up or
down, and then convert back to RGB using one of those algorithms (they are
all based on the same source, so they ought to be equivalent...I didn't
check them closely to make sure though).
Pete