public static bool Pixelate2(ref Bitmap bmp, int zone) { BmpProc32 src = new BmpProc32(bmp); if ((zone < 2) | (zone > 30)) { return(false); } int w = bmp.Width; int h = bmp.Height; int ir, count, sumr, sumg, sumb; byte[,] rr = new byte[w / zone + 1, h / zone + 1]; byte[,] gg = new byte[w / zone + 1, h / zone + 1]; byte[,] bb = new byte[w / zone + 1, h / zone + 1]; int countX, countY; byte rrr, ggg, bbb; countY = 0; for (int y = 0; y < h - 1; y += zone) { countX = 0; for (int x = 0; x < w - 1; x += zone) { count = sumr = sumg = sumb = 0; for (int iy = y; iy < y + zone; iy++) { for (int ix = x; ix < x + zone; ix++) { if ((iy > h - 1) | (ix > w - 1)) { continue; } count++; ir = src.IndexR(ix, iy); sumr += src[ir]; sumg += src[ir - 1]; sumb += src[ir - 2]; } } sumr = sumr / count; sumg = sumg / count; sumb = sumb / count; rr[countX, countY] = (byte)sumr; gg[countX, countY] = (byte)sumg; bb[countX, countY] = (byte)sumb; rrr = (byte)sumr; ggg = (byte)sumg; bbb = (byte)sumb; if ((sumr < 230) & (sumr > 15)) { rrr = (byte)(sumr - 15); } if ((sumg < 230) & (sumg > 15)) { ggg = (byte)(sumg - 15); } if ((sumb < 230) & (sumb > 15)) { bbb = (byte)(sumb - 15); } for (int iy = y; iy < y + zone; iy++) { for (int ix = x; ix < x + zone; ix++) { if ((iy > h - 1) | (ix > w - 1)) { continue; } ir = src.IndexR(ix, iy); src[ir] = rrr; src[ir - 1] = ggg; src[ir - 2] = bbb; } } countX++; } countY++; } src.Dispose(); countY = 0; SolidBrush br = new SolidBrush(Color.Black); Point[] pt = new Point[3]; Graphics g = Graphics.FromImage(bmp); g.SmoothingMode = SmoothingMode.AntiAlias; for (int y = 0; y < h - 1; y += zone) { countX = 0; for (int x = 0; x < w - 1; x += zone) { rrr = rr[countX, countY]; ggg = gg[countX, countY]; bbb = bb[countX, countY]; if ((rrr < 230) & (rrr > 15)) { rrr = (byte)(rrr + 15); } if ((ggg < 230) & (ggg > 15)) { ggg = (byte)(ggg + 15); } if ((bbb < 230) & (bbb > 15)) { bbb = (byte)(bbb + 15); } br.Color = Color.FromArgb(rrr, ggg, bbb); pt[0].X = x; pt[0].Y = y; pt[1].X = x + zone; pt[1].Y = y; pt[2].X = x; pt[2].Y = y + zone; g.FillPolygon(br, pt); countX++; } countY++; } g.Dispose(); br.Dispose(); return(true); }
public static bool Pixelate1(ref Bitmap bmp, int zone) { BmpProc32 src = new BmpProc32(bmp); if ((zone < 2) | (zone > 30)) { return(false); } int w = bmp.Width; int h = bmp.Height; int ir, count, sumr, sumg, sumb; for (int y = 0; y < h; y += zone) { for (int x = 0; x < w; x += zone) { count = sumr = sumg = sumb = 0; for (int iy = y; iy < y + zone; iy++) { for (int ix = x; ix < x + zone; ix++) { if ((iy > h - 1) | (ix > w - 1)) { continue; } count++; ir = src.IndexR(ix, iy); sumr += src[ir]; sumg += src[ir - 1]; sumb += src[ir - 2]; } } sumr = sumr / count; sumg = sumg / count; sumb = sumb / count; for (int iy = y; iy < y + zone; iy++) { for (int ix = x; ix < x + zone; ix++) { if ((iy > h - 1) | (ix > w - 1)) { continue; } ir = src.IndexR(ix, iy); src[ir] = (byte)sumr; src[ir - 1] = (byte)sumg; src[ir - 2] = (byte)sumb; } } } } src.Dispose(); return(true); }