【文件属性】:
文件名称:获取图像灰度
文件大小:35KB
文件格式:DOC
更新时间:2016-12-24 09:20:19
灰度值
如何从图像中提取灰度Color currentColor;
int r;
Bitmap currentBitmap = new Bitmap(picBox.Image);
Graphics g = Graphics.FromImage(currentBitmap);
for (int w = 0; w < currentBitmap.Width; w++)
{
for (int h = 0; h < currentBitmap.Height; h++)
{
currentColor = currentBitmap.GetPixel(w, h);
r = (currentColor.R + currentColor.G + currentColor.B) / 3;
currentBitmap.SetPixel(w, h, Color.FromArgb(r, r, r));
}
}
g.DrawImage(currentBitmap, 0, 0);
picBox.Image = currentBitmap;
g.Dispose();