#region 改变图片颜色
/// summary>
/// 改变图片的颜色
/// /summary>
/// param name="filePath">图片的完整路径/param>
/// param name="colorIndex">改变的颜色,true为灰色,false为彩色/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>
/// 获取彩色单点像素
/// /summary>
/// param name="posClr">单点像素/param>
/// returns>int/returns>
private int GetHongNumColor(Color posClr)
{
return (posClr.R * 19595 + posClr.G * 38469 + posClr.B * 7472) >> 16;
}
/// summary>
/// 获取灰色单点像素
/// /summary>
/// param name="posClr">单点像素/param>
/// returns>Color/returns>
private int GetGrayNumColor(Color posClr)
{
//要改变ARGB
return (posClr.R * 19595 + posClr.G * 38469 + posClr.B * 7472) >> 16;
}
#endregion 改变图片颜色