/**////<summary> /// 图像明暗调整 ///</summary> ///<param name="b">原始图</param> ///<param name="degree">亮度[-255, 255]</param> ///<returns></returns> publicstatic Bitmap KiLighten(Bitmap b, int degree) ...{ if (b ==null) ...{ returnnull; } 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 ...{ returnnull; } }// end of Lighten