标签:
Color C1, C2, C3, C4; int r1, r2, r3, r4, g1, g2, g3, g4, b1, b2, b3, b4, rx, ry, gx, gy, bx, by, rr, gg, bb; Bitmap bmp = new Bitmap(pictureBox1.Image); Bitmap tmp = (Bitmap)bmp.Clone(); for (int i = 0; i < bmp.Width - 1; i++) for (int j = 0; j < bmp.Height - 1; j++) { //获得相邻4个像素颜色值 ///斜对角 C1 = bmp.GetPixel(i, j); C2 = bmp.GetPixel(i + 1, j + 1); C3 = bmp.GetPixel(i + 1, j); C4 = bmp.GetPixel(i, j + 1); //红色分量值 r1 = C1.R; r2 = C2.R; r3 = C3.R; r4 = C4.R; rx = r1 - r2; ry = r3 - r4; rr = Math.Abs(rx) + Math.Abs(ry) + 128; //绿色分量值 g1 = C1.G; g2 = C2.G; g3 = C3.G; g4 = C4.G; gx = g1 - g2; gy = g3 - g4; gg = Math.Abs(gx) + Math.Abs(gy) + 128; //蓝色分量值 b1 = C1.B; b2 = C2.B; b3 = C3.B; b4 = C4.B; bx = b1 - b2; by = b3 - b4; bb = Math.Abs(bx) + Math.Abs(by) + 128; //处理颜色值溢出 rr = rr > 255 ? 255 : rr; rr = rr < 0 ? 0 : rr; gg = gg > 255 ? 255 : gg; gg = gg < 0 ? 0 : gg; bb = bb > 255 ? 255 : bb; bb = bb < 0 ? 0 : bb; tmp.SetPixel(i, j, Color.FromArgb(rr, gg, bb)); } pictureBox2.Image = tmp;
标签:
原文地址:http://www.cnblogs.com/wjshan0808/p/4241177.html