最近奇葩经理提出了奇葩的需求,要能在网站上改变图片的颜色,比如灰色的变成彩色,彩色的变成灰色,尼玛楼主的感受你们不懂!于是有了下面的代码。。。
用法:调用update_pixelColor方法并传参数即可 
C#代码  
![]()
class="star" src="/Upload/Images/2014081117/40B102E0EF997EA6.png" alt="收藏代码" />
- #region 改变图片颜色  
-   
- 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);  
- }  
-   
- private int GetHongNumColor(Color posClr)  
- {  
-     return (posClr.R * 19595 + posClr.G * 38469 + posClr.B * 7472) >> 16;  
- }  
-   
- private int GetGrayNumColor(Color posClr)  
- {  
-     
-     return (posClr.R * 19595 + posClr.G * 38469 + posClr.B * 7472) >> 16;  
- }  
-  
- #endregion 改变图片颜色  
这个转换的比较慢 看到编程人生上有关于这方面的总结,哪天来研究一下