iT邦幫忙

DAY 14
1

程式隨手寫系列 第 14

小功能(11)

private void button1_Click(object sender, EventArgs e)
        {
            Graphics graphis = this.CreateGraphics();
            Bitmap bitmap = new Bitmap(this.BackgroundImage);
            int width, height, i, j, avg, pixel;
            Color color, newcolor;
            RectangleF rect;
            width = bitmap.Width;
            height = bitmap.Height;
            rect = new RectangleF(0, 0, width, height);
            Bitmap thebitmap = bitmap.Clone(rect, System.Drawing.Imaging.PixelFormat.DontCare);
            i = 0;
            while (i<width-1)
            {
                j = 0;
                while (j<height-1)
                {
                    color = thebitmap.GetPixel(i, j);
                    avg = (color.R + color.G + color.B) / 3;
                    pixel = 0;
                    if (avg >= 128)
                        pixel = 255;
                    else
                        pixel = 0;
                    newcolor = Color.FromArgb(255, pixel, pixel, pixel);
                    bitmap.SetPixel(i, j, newcolor);
                    j = j + 1;
                }
                i = i + 1;
            }
            graphis.Clear(Color.WhiteSmoke);
            graphis.DrawImage(bitmap, new Rectangle(0, 0, width, height));
        }

把圖片顏色調整為黑白色


上一篇
小功能(10)
下一篇
小功能(12)
系列文
程式隨手寫20
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言