In this paper, the implementation method of C # Color image grayscale is described. Share to everyone for your reference. Here's how:
The main function code is as follows:
The code is as follows:
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;
}
In addition to the Declaration,
Running GuestArticles are original, reproduced please link to the form of the address of this article
Example of grayscale algorithm for C # color image
This address: http://www.paobuke.com/develop/c-develop/pbk23444.html
Related content solutions to path problems when connecting to FTP in C # custom logging C # implements Ruby's negative indexer C # implements a method to get the same name property in different objects
C # How to implement Chinese characters to pinyin or Pinyin first letter C #? D??? 3?? èí?tê?? Ò?°2x°êμ?? ′ú???? íc# implementation of custom serialization ISerializable the serialized generic class instance implemented by C #
Example of grayscale algorithm for C # color image