Use asp.net to change the color of an image, such as gray to color,
Recently, the manager has raised a strange demand to change the color of pictures on the website, for example, gray becomes color and color turns gray. You don't understand the feeling of NIMA! So we have the following code.
Usage: Call the update_pixelColor method and pass parameters.
# Region change the image color /// <summary> /// change the image color /// </summary> /// <param name = "filePath"> complete path of the image </param> /// <param name = "colorIndex"> changed color, true is gray, false is 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> /// obtain the color Single Point pixel /// </summary> /// <param name = "posClr"> Single Point pixel </param> /// <returns> int </returns> private int GetHongNumColor (Color posClr) {return (posClr. r* 19595 + posClr. G * 38469 + posClr. B * 7472)> 16 ;} /// <summary> /// obtain the gray Single Point pixel /// </summary> /// <param name = "posClr"> Single Point pixel </param> /// <returns> Color </returns> private int GetGrayNumColor (Color posClr) {// ARGB return (posClr. r* 19595 + posClr. G * 38469 + posClr. B * 7472)> 16;} # change the image color