/// <summary> /// 图片灰度反转 /// </summary> /// <param name="bmp"></param> /// <returns></returns> public static Bitmap Reverse(Bitmap bmp) { if (bmp == null) return bmp; Rectangle bmpRect = new Rectangle(0, 0, bmp.Width, bmp.Height); BitmapData bmpData = bmp.LockBits(bmpRect, ImageLockMode.ReadWrite, bmp.PixelFormat); int bytes = bmpData.Stride * bmp.Height; byte[] rgbValues = new byte[bytes]; IntPtr ptr = bmpData.Scan0; Marshal.Copy(ptr, rgbValues, 0, bytes); for (int y = 0; y < bmp.Height; y++) for (int x = 0; x < bmp.Width * 3; x ++) rgbValues[y * bmpData.Stride + x] = (byte)(255 - rgbValues[y * bmpData.Stride + x]); Marshal.Copy(rgbValues, 0, ptr, bytes); bmp.UnlockBits(bmpData); return bmp; }