Mega Code Archive

 
Categories / C# / 2D Graphics
 

To Grey scale

using System; using System.Collections.Generic; using System.Windows.Media; using System.Reflection; using System.Globalization; namespace NASA.BeAMartian.Utils {     public class ColorUtils     {         public static void ToGreyscale(byte r, byte g, byte b, out byte rn, out byte gn, out byte bn)         {             double lum = GetLuminance(r, g, b);             rn = (byte)(r * lum);             gn = (byte)(g * lum);             bn = (byte)(b * lum);         }                 public static double GetLuminance(byte r, byte g, byte b)         {             return  0.299 * r + 0.587 * g + 0.114 * b;         }     } }