I have a project on image processing. I have a picturebox with an image loaded in it via a openfiledialog box.
I was trying to zoom an image in the picturebox by certain pecentage i.e 50%, 100% 150% and 200% . All this is done when a user clicks on a menutool strip option.
I have the following code but it is not working:
private void toolStripMenuItem2_Click(object sender, EventArgs e) //coding for 50% zoom
{
if (img != null)
{
Graphics g = Graphics.FromImage(img);
int zoom=50/100;
int newwidth = Convert.ToInt32(pictureBox1.Width * zoom);
int newheight = Convert.ToInt32(pictureBox1.Height * zoom);
Rectangle r = new Rectangle(this.AutoScrollPosition.X,this.AutoScrollPosition.Y,newwidth, newheight);
// pictureBox1.Invalidate();
g.DrawImage(img, r);
pictureBox1.Image = img;
}
}
Please help......