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));
}
把圖片顏色調整為黑白色