Recently, a wonderful flower manager put forward the needs of exotic flowers, to be able to change the color of the picture on the site, such as the gray color, color into the gray, the feelings of the landlord you do not understand! So I have the following code ...
Usage: Call the Update_pixelcolor method and pass the parameter
#region Change the picture color///<summary>///Change the color of the picture///</summary>///<param name= "FilePath" > The full path of the picture </par am>///<param name= "ColorIndex" > Changed color, true to gray, false to color </param> public void Update_pixelcolor (string
FilePath, bool ColorIndex) {Bitmap bmp = new Bitmap (Bitmap.fromfile (FilePath));
int value = 0; for (int i = 0; i < BMP. Height; i++) {for (int j = 0; J < BMP.) Width; J + +) {if (ColorIndex) value = this. Getgraynumcolor (BMP.
GetPixel (J, i)); else value = this. Gethongnumcolor (BMP.
GetPixel (J, i)); Bmp.
SetPixel (J, I, Color.FromArgb (value, value, value)); } BMP.
Save (FilePath); ///<summary>///Get color single pixel///</summary>///<param name= "POSCLR" > Single point pixel </param>///<re turns>int</returns> private int Gethongnumcolor (Color posclr) {return (POSCLR.R * 19595 + posclr.g * 38469 +
POSCLR.B * 7472) >> 16; ///<summary>///Get gray single point pixel///</summary>///<param name= "PosCLR "> Single point pixel </param>///<returns>Color</returns> private int getgraynumcolor (Color posclr) {//To change a
RGB return (POSCLR.R * 19595 + posclr.g * 38469 + posclr.b * 7472) >> 16; #endregion change the color of the picture