您的位置:首页 > 编程语言 > C#

C# (灰度)加权平均法将图片转换为灰度图

2016-10-09 10:55 281 查看


private Bitmap ToG(string file)
{
using (Bitmap o = new Bitmap(file))
{
Bitmap g = new Bitmap(o.Width, o.Height);
for (int i = 0; i < o.Width; i++)
{
for (int j = 0; j < o.Height; j++)
{
Color c = o.GetPixel(i, j);
//灰度加权平均法公式
int rgb = (int)(c.R * 0.299 + c.G * 0.587 + c.B * 0.114);
g.SetPixel(i, j, Color.FromArgb(rgb, rgb, rgb));
}
}
return g;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: