C#圖像對比度調整的方法
更新時間:2015年04月24日 09:54:35 作者:滄海一粟……
這篇文章主要介紹了C#圖像對比度調整的方法,涉及C#實現圖像對比度操作的相關技巧,需要的朋友可以參考下
本文實例講述了C#圖像對比度調整的方法。分享給大家供大家參考。具體如下:
//定義對比度調整函數 private static Bitmap ContrastP(Bitmap a, double v) { System.Drawing.Imaging.BitmapData bmpData = a.LockBits(new Rectangle(0, 0, a.Width, a.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb); int bytes = a.Width * a.Height * 3; IntPtr ptr = bmpData.Scan0; int stride = bmpData.Stride; unsafe { byte* p = (byte*)ptr; int temp; for (int j = 0; j < a.Height; j++) { for (int i = 0; i < a.Width * 3; i++) { temp = (int)((p[0] - 127) * v + 127); temp = (temp > 255) ? 255 : temp < 0 ? 0 : temp; p[0] = (byte)temp; p++; } p += stride - a.Width * 3; } } a.UnlockBits(bmpData); return a; }
希望本文所述對大家的C#程序設計有所幫助。
相關文章
C#創(chuàng)建、部署、調用WebService圖文實例詳解
本文主要用詳細的圖文給大家介紹C#創(chuàng)建、部署、調用WebService的全部過程以及中間需要避免的問題。2017-11-11