C#图像处理之木刻效果实现方法
程序员文章站
2022-05-15 14:23:17
本文实例讲述了c#图像处理之木刻效果实现方法。分享给大家供大家参考。具体如下:
//木刻效果
public bitmap pfiltermuke(bitmap...
本文实例讲述了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#程序设计有所帮助。
上一篇: 理解C#中的枚举(简明易懂)
下一篇: Vue学习之生命周期钩子小结(四)