标签:
Color C; int r, g, b, rV, gV, bV, rT, gT, bT, y, z; Bitmap bmp = new Bitmap(pictureBox1.Image);//创建Bitmap对象 Bitmap tmp = (Bitmap)bmp.Clone(); //马赛克为5*5阵列 for (int i = 0; i < bmp.Width - 5; i += 5) for (int j = 0; j < bmp.Height - 5; j += 5) { rT = 0; gT = 0; bT = 0; //获取区域块的像素颜色分量值 for (y = 0; y <= 5; y++) for (z = 0; z <= 5; z++) { C = bmp.GetPixel(i + y, j + z); r = C.R; g = C.G; b = C.B; rT = rT + r; gT = gT + g; bT = bT + b; } //取平均值 rV = (int)rT / 25; gV = (int)gT / 25; bV = (int)bT / 25; //处理颜色值溢出 rV = rV > 255 ? 255 : rV; rV = rV < 0 ? 0 : rV; gV = gV > 255 ? 255 : gV; gV = gV < 0 ? 0 : gV; bV = bV > 255 ? 255 : bV; bV = bV < 0 ? 0 : bV; //用平均值绘制5*5区域图像 for (y = 0; y <= 5; y++) for (z = 0; z <= 5; z++) tmp.SetPixel(i + y, j + z, Color.FromArgb(rV, gV, bV)); } pictureBox2.Image = tmp;
标签:
原文地址:http://www.cnblogs.com/wjshan0808/p/4241071.html