实现效果:
知识运用:
通过Bitmap对象的GetPixel方法获取各像素点的颜色;然后分别使用Color对象的R G B属性
获取各像素点的元素值, 使用这项值减去相邻的像素点的元素值再加上128
实现代码:
private void button1_Click(object sender, EventArgs e) { Bitmap bitmap=new Bitmap(this.BackgroundImage); for (int i = 0; i < bitmap.Width-1;i++ ) { for (int j = 0; j < bitmap.Height-1;j++ ) { Color color1 = bitmap.GetPixel(i,j); Color color2 = bitmap.GetPixel(i+1,j+1); int red = Math.Abs(color1.R - color2.R + 128); int green = Math.Abs(color1.G - color2.G + 128); int blue = Math.Abs(color1.B - color2.B + 128); //颜色处理 if (red > 255) red = 255; if (red < 0) red = 0; if (green > 255) green = 255; if (green < 0) green = 0; if (blue > 255) blue = 255; if (blue < 0) blue = 0; //为像素点重新着色 bitmap.SetPixel(i,j,Color.FromArgb(red,green,blue)); } } this.BackgroundImage = bitmap; }