首页 > 代码库 > 积木效果

积木效果

int avg, iPixel;            Color C, newC;            Graphics g = this.CreateGraphics();            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++)                {                    C = tmp.GetPixel(i, j);                    avg = (C.R + C.G + C.B) / 3;                    iPixel = 0;                    if (avg >= 128)                        iPixel = 255;                    newC = Color.FromArgb(255, iPixel, iPixel, iPixel);                    tmp.SetPixel(i, j, newC);                 }            g.Clear(Color.WhiteSmoke);
g.Dispose();
pictureBox2.Image = tmp;

技术分享

积木效果