drawn an rectangle on the image using picture box.
quires
1. when tried to zoom image the drawn rectangles needs to be placed on the drawn area.
2. Also draw another rectangle (in zoomed mode).
3. when i zoomed out the rectangle needs to resized.
How can i achieve this.
I achieved this by using graphics.drawrectangle but i don't want to draw rectangle on the image because it's stay permanently on the image (like to cahnge size when user likes).
Tried the below logic (for Xand y Co-ordinates) and it varies from point to point on the Image.
//used in zoomIn menthod
rect1 = new Rectangle(rectangles[c].X+((pictureBox1.Width/rectangles[c].Height)+(pictureBox1.Width/100)),rectangles[c].Y+((pictureBox1.Height/rectangles[c].Width)), rectangles[c].Width, rectangles[c].Height);
rectangles.RemoveAt(c);
rectangles.Insert(c, rect1);
rect = new Rectangle(0, 0, 0, 0);
Please help on this......
//getting size of picture box in sz1
public void ZoomIn()
{
//pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
if (sz1.Width >= 800 * 6)
MessageBox.Show("Max ZoomIn");
else
{
sz1.Width += 100;
sz1.Height += 100;
pictureBox1.Size = sz1;
pictureBox1.Invalidate();
}
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (mybitmap == null)
{
mybitmap = new Bitmap(pictureBox1.Image.Width, pictureBox1.Image.Height);
mybitmap.SetResolution(300, 300);
}
rect = new Rectangle(e.X, e.Y, 0, 0);
pictureBox1.Invalidate();
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
if (mybitmap == null)
{
return;
}
using (Pen pen = new Pen(Color.Green, 2))
{
foreach (Rectangle r in rectangles)
{
e.Graphics.DrawRectangle(pen, r);
e.Graphics.DrawString(lab[c].ToString(), new Font(lab[c].ToString(), 8F), new SolidBrush(label1.ForeColor), r);
}
}
}