public static Bitmap KiMosaic(Bitmap b, int val) { if (b.Equals(null)) { return null; } int w = b.Width; int h = b.Height; int stdR, stdG, stdB; stdR = 0; stdG = 0; stdB = 0; BitmapData srcData = b.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); unsafe { byte* p = (byte*)srcData.Scan0.ToPointer(); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { if (y % val == 0) { if (x % val == 0) { stdR = p[2]; stdG = p[1]; stdB = p[0]; } else { p[0] = (byte)stdB; p[1] = (byte)stdG; p[2] = (byte)stdR; } } else { // 复制上一行 byte * pTemp = p - srcData.Stride; p[0] = (byte)pTemp[0]; p[1] = (byte)pTemp[1]; p[2] = (byte)pTemp[2]; } p += 3; } // end of x p += srcData.Stride - w * 3; } // end of y b.UnlockBits(srcData); } return b; } |
欢迎访问最专业的网吧论坛,无盘论坛,网吧经营,网咖管理,网吧专业论坛
https://bbs.txwb.com
关注天下网吧微信/下载天下网吧APP/天下网吧小程序,一起来超精彩
|
本文来源:vczx 作者:佚名