Http://www.jb51.net/article/37067.htm
public static Bitmap Makegrayscale (Bitmap original)
{
Create a blank bitmap the same size as original
Bitmap Newbitmap = new Bitmap (original. Width, original. Height);
Get a Graphics object from the new image
Graphics g = graphics.fromimage (Newbitmap);
Create the Grayscale ColorMatrix
System.Drawing.Imaging.ColorMatrix ColorMatrix = new System.Drawing.Imaging.ColorMatrix (
New float[][]
{
New float[] {. 3f,. 3f,. 3f, 0, 0},
New float[] {. 59f,. 59f,. 59f, 0, 0},
New float[] {. 11f,. 11f,. 11f, 0, 0},
New float[] {0, 0, 0, 1, 0},
New float[] {0, 0, 0, 0, 1}
});
Create some image attributes
System.Drawing.Imaging.ImageAttributes attributes = new System.Drawing.Imaging.ImageAttributes ();
Set the color matrix attribute
Attributes. SetColorMatrix (ColorMatrix);
Draw the original image on the new image
Using the grayscale color matrix
G.drawimage (Original, new Rectangle (0, 0, original. Width, original. Height),
0, 0, original. Width, original. Height, GraphicsUnit.Pixel, attributes);
Dispose the Graphics object
G.dispose ();
return newbitmap;
}
Analysis of the implementation code of C # color image grayscale algorithm