当前位置: 移动技术网 > IT编程>开发语言>c# > C#图像处理之木刻效果实现方法

C#图像处理之木刻效果实现方法

2019年07月18日  | 移动技术网IT编程  | 我要评论

本文实例讲述了c#图像处理之木刻效果实现方法。分享给大家供大家参考。具体如下:

//木刻效果
public bitmap pfiltermuke(bitmap src)
{
 try
 {
  bitmap a = new bitmap(src);
  rectangle rect = new rectangle(0, 0, a.width, a.height);
  system.drawing.imaging.bitmapdata bmpdata = a.lockbits(rect, system.drawing.imaging.imagelockmode.readwrite, system.drawing.imaging.pixelformat.format24bpprgb);
  int stride = bmpdata.stride;
  unsafe
  {
   byte* pin = (byte*)bmpdata.scan0.topointer();
   byte* p;
   int r, g, b;
   int temp = 0;
   for (int y = 0; y < a.height; y++)
   {
   for (int x = 0; x < a.width; x++)
   {
    p = pin;
    b = p[0];
    g = p[1];
    r = p[2];
    temp = (byte)((b + g + r) / 3);
    if (temp >= 122.5)
    {
    p[2] = 0;
    p[1] = 0;
    p[0] = 0;
    }
    else
    {
    p[2] = (byte)255;
    p[1] = (byte)255;
    p[0] = (byte)255;
    }
    pin += 3;
   }
   pin += stride - a.width * 3;
   }
  }
  a.unlockbits(bmpdata);
  return a;
 }
 catch (exception e)
 {
  messagebox.show(e.message.tostring());
  return null;
 }
}

原图:

效果图:

希望本文所述对大家的c#程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网