当前位置: 移动技术网 > IT编程>开发语言>c# > C#图像线性变换的方法

C#图像线性变换的方法

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

本文实例讲述了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#程序设计有所帮助。

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

相关文章:

验证码:
移动技术网