winform用GDI+对图片进行灰度处理
1个回答
展开全部
主要用一些算法实现
private void button_Click(object sender, EventArgs e)
{
int width = this.pictureBox1.Image.Width;
int heigh = this.pictureBox1.Image.Height;
Bitmap oldbmp = (Bitmap)this.pictureBox1.Image;
Bitmap newbmp = new Bitmap(width, heigh);
Color pixel;
for (int x = 0; x < width; x++)
{
for (int y = 0; y < heigh; y++)
{
int r, g, b,result;
//获取原图中该像素点的三原色对象
pixel = oldbmp.GetPixel(x, y);
r = pixel.R;
g = pixel.G;
b = pixel.B;
result=(r+b+g)/3;
//设置新图片中该像素点的三原色
newbmp.SetPixel(x, y, Color.FromArgb(result, result, result));
}
}
this.pictureBox1.Image = newbmp;
}
private void button_Click(object sender, EventArgs e)
{
int width = this.pictureBox1.Image.Width;
int heigh = this.pictureBox1.Image.Height;
Bitmap oldbmp = (Bitmap)this.pictureBox1.Image;
Bitmap newbmp = new Bitmap(width, heigh);
Color pixel;
for (int x = 0; x < width; x++)
{
for (int y = 0; y < heigh; y++)
{
int r, g, b,result;
//获取原图中该像素点的三原色对象
pixel = oldbmp.GetPixel(x, y);
r = pixel.R;
g = pixel.G;
b = pixel.B;
result=(r+b+g)/3;
//设置新图片中该像素点的三原色
newbmp.SetPixel(x, y, Color.FromArgb(result, result, result));
}
}
this.pictureBox1.Image = newbmp;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询