標籤:images 記錄 offset ges byte read stat div lease
昨天去客戶那裡測試,需求才開始,所以很簡單,就是測一下能不能接受到視頻或圖片,然後儲存下來,現場客戶說亮度不夠,然後學了一下C#調節圖片亮度,記錄一下
學習的文章在這:http://blog.csdn.net/kenkao/article/details/3148091
/// <summary> /// 映像明暗調整 /// </summary> /// <param name="b">原始圖</param> /// <param name="degree">亮度[-255, 255]</param> /// <returns></returns> public static Bitmap KiLighten(Bitmap b, int degree) { if (b == null) { return null; } if (degree < -255) degree = -255; if (degree > 255) degree = 255; try { int width = b.Width; int height = b.Height; int pix = 0; BitmapData data = b.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); unsafe { byte* p = (byte*)data.Scan0; int offset = data.Stride - width * 3; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { // 處理指定位置像素的亮度 for (int i = 0; i < 3; i++) { pix = p[i] + degree; if (degree < 0) p[i] = (byte)Math.Max(0, pix); if (degree > 0) p[i] = (byte)Math.Min(255, pix); } // i p += 3; } // x p += offset; } // y } b.UnlockBits(data); return b; } catch { return null; } } // end of Lighten
View Code
然後調用
string savePath = @"C:\Users\wjr\Desktop\出差用\1.png"; Bitmap img = new Bitmap(@"C:\Users\wjr\Desktop\出差用\WindowsFormsApplication1\WindowsFormsApplication1\WindowsFormsApplication1\bin\Release\Capture\20170417 025826019.png"); Bitmap a = KiLighten(img, 20); a.Save(savePath);
Bitmap a = KiLighten(img, 20);
我這裡設定的是20,範圍是-255~255,所以0是原圖片亮度,我設定的20,所以圖片亮度想過顯示不明顯,我弄個100的,看下效果
C#調節圖片亮度