Hi,
1). You can set the SizeMode property of the PictureBox to AutoSize, then whenever the image size changes, the PictureBox will adjust its size accordingly.
2). You can save the image with the format you need by ImageFormat enumeration. Something like this:
this.pictureBox1.Image.Save(@"c:\test2\a.png", ImageFormat.Png);
3). For making the image gray, one approach is to loop through the pixels in the bitmap,retrieve the color on the specified pixel, and change it using some algorithm, for example, we can do someting like this to gray the image
Code Snippet
void button1_Click(object sender, EventArgs e)
{
Bitmap bmp = new Bitmap(this.pictureBox1.Image.Width,
this.pictureBox1.Image.Height);
Bitmap img = this.pictureBox1.Image as Bitmap;
for (int h = 0; h < bmp.Height; h++)
{
for (int w = 0; w < bmp.Width; w++)
{
Color c = img.GetPixel(w, h);
Color newColor = Color.FromArgb(
(int)(0.5 * c.R + 0.3 * c.G + 0.2 * c.B),
(int)(0.5 * c.R + 0.3 * c.G + 0.2 * c.B),
(int)(0.5 * c.R + 0.3 * c.G + 0.2 * c.B));
bmp.SetPixel(w, h, newColor);
}
}
this.pictureBox1.Image = bmp;
}
Best Regards
Zhi-xin Ye |