Use asp.net to change the color of a picture on a webpage such as grey color _ practical Tips

Source: Internet
Author: User

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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.