private void button1_Click(object sender, System.EventArgs e)
{
Bitmap bitmap = new Bitmap("C:\\640480.bmp");
int bwidth = bitmap.Width;
int bheight = bitmap.Height;
this.Width=bwidth;
this.Height=bheight;
int i, j;
byte gray;
for (i = 0; i<bwidth; i++)
{
for (j=0; j<bheight; j++)
{
Color pixelColor = bitmap.GetPixel(i, j);
int r = pixelColor.R; // the Red component
int g = pixelColor.G; // the Red component
int b = pixelColor.B; // the Blue component
gray=Convert.ToByte(r*0.3+g*0.6+b*0.1);
Color newColor = Color.FromArgb(gray, gray, gray);
bitmap.SetPixel(i, j, newColor);
}
}
this.BackgroundImage = bitmap;
}
Convert.ToByte(r*0.3+g*0.6+b*0.1);
답글삭제