本文实例讲述了c#图像线性变换的方法。分享给大家供大家参考。具体如下:
//定义图像线性运算函数(y=kx+v) private static bitmap linearop(bitmap a, double k, double v) { rectangle rect = new rectangle(0, 0, a.width, a.height); system.drawing.imaging.bitmapdata srcdata = a.lockbits(rect, system.drawing.imaging.imagelockmode.readwrite, a.pixelformat); intptr ptr = srcdata.scan0; int bytes = 0; bytes = srcdata.stride * a.height; byte[] grayvalues = new byte[bytes]; system.runtime.interopservices.marshal.copy(ptr, grayvalues, 0, bytes); int temp = 0; for (int i = 0; i < bytes; i++) { temp = (int)(k * grayvalues[i] + v + 0.5); temp = (temp > 255) ? 255 : temp < 0 ? 0 : temp; grayvalues[i] = (byte)temp; } system.runtime.interopservices.marshal.copy(grayvalues, 0, ptr, bytes); a.unlockbits(srcdata); return a; }
希望本文所述对大家的c#程序设计有所帮助。
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
浅谈Visual Studio 2019 Vue项目的目录结构
网友评论