先看效果:
处理后:
代码如下:
Color c1=new Color();
Color c2=new Color();
Color c3=new Color();
Color c4=new Color();
int rr,gg,bb,r1,r2,r3,r4,fxr,fyr,i,j;
int g1,g2,g3,g4,fxg,fyg,b1,b2,b3,b4,fxb,fyb;
Bitmap box1=new Bitmap(openImage.Image);
for(i=0;i<openImage.Image.Width-2;i++)
{
for(j=0;j<openImage.Image.Height-2;j++)
{
c1=box1.GetPixel(i,j);
c2=box1.GetPixel(i+1,j+1);
c3=box1.GetPixel(i+1,j);
c4=box1.GetPixel(i,j+1);
r1=c1.R;
r2=c2.R;
r3=c3.R;
r4=c4.R;
fxr=r1-r2;
fyr=r3-r4;
rr=Math.Abs(fxr)+Math.Abs(fyr)+128;
if(rr<0)rr=0;
if(rr>255)rr=255;
g1=c1.G;
g2=c2.G;
g3=c3.G;
g4=c4.G;
fxg=g1-g2;
fyg=g3-g4;
gg=Math.Abs(fxg)+Math.Abs(fyg)+128;
if(gg<0)gg=0;
if(gg>255)gg=255;
b1=c1.B;
b2=c2.B;
b3=c3.B;
b4=c4.B;
fxb=b1-b2;
fyb=b3-b4;
bb=Math.Abs(fxb)+Math.Abs(fyb)+128;
if(bb<0)bb=0;
if(bb>255)bb=255;
Color cc=Color.FromArgb(rr,gg,bb);//由颜色分量值创建Color结构
box1.SetPixel(i,j,cc);
openImage.Refresh();
openImage.Image=box1;
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)