Bitmap bmp = new Bitmap(pictureBox1.Image);//创建Bitmap对象
for (int i = 0; i < bmp.Width - 1; i++)
{
for (int j = 0; j < bmp.Height - 1; j++)
{
//获取相邻两个像素的R、G、B值
Color color = bmp.GetPixel(i, j);
Color colorLeft = bmp.GetPixel(i + 1, j + 1);
//67用来控制图片的最低灰度
int r = Math.Max(67, Math.Min(255, Math.Abs(color.R - colorLeft.R + 128)));
int g = Math.Max(67, Math.Min(255, Math.Abs(color.G - colorLeft.G + 128)));
int b = Math.Max(67, Math.Min(255, Math.Abs(color.B - colorLeft.B + 128)));
Color colorResult = Color.FromArgb(255, r, g, b);//颜色值
bmp.SetPixel(i, j, colorResult);//设置像素的颜色值
}
pictureBox2.Image = bmp;
}