C#圖象線性變換的辦法。本站提示廣大學習愛好者:(C#圖象線性變換的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#圖象線性變換的辦法正文
本文實例講述了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#法式設計有所贊助。