Q:

Sorting Color in C# on the basis of brightness or YIQ scale

I am looking for sorting some colors in our project on the basis of the brightness, so probably I need YIQ representation of the color on basis of which I can sort.
So I am pricesely looking for the YIQ representaion of some given RGB format color in C#
I found this formula on wiki and some other sites for conversion from RGB to YIQ scale:
Here is the RGB -> YIQ conversion:
[ Y ]     [ 0.299   0.587   0.114 ] [ R ]
[ I ]  =  [ 0.596  -0.275  -0.321 ] [ G ]
[ Q ]     [ 0.212  -0.523   0.311 ] [ B ]

But now how to get the Color value in C# from this Y, I and Q values which we would get from this formula.
So if I have this color: #FF832727 which is in RGB format, how to get its corresponding color in YIQ scale.

A:

Possible implementation, if I´ve understood your right
List<Color> colors = new List<Color> {
  Color.Wheat,
  Color.Black,
  Color.Red,
  Color.FromArgb(unchecked ((int)0xFF832727U))
};

// You don't need convert colors into YIQ (i.e. matrix multiplication)
// just compare brightness (Y component)
colors.Sort((Comparison<Color>) (
  (Color left, Color right) => 
     (left.R * 299 + left.G * 587 + left.B * 114).CompareTo(
      right.R * 299 + right.G * 587 + right.B * 114)
  ));

