I have a picturebox with SizeMode=Zoom. I have rectangles (annotations) drawn on the picturebox too.
This is the code that rotates the image in the picturebox (in click event of a button)
Image img = picZoom.Image;
img.RotateFlip(RotateFlipType.Rotate90FlipXY);
picZoom.Image = img;
RotationgAngle += 90;
This, of course, fires off the Paint event, which contains the following:
for (int i = 0; i <= Annotations.Items.Count - 1; i++)
{
Rectangle r = functions.ZoomRectangle(Annotations.Items[i].Box, picZoom, true);
using (Matrix m = new Matrix())
{
m.RotateAt(RotationgAngle, new PointF(r.Left + (r.Width / 2), r.Top + (r.Height / 2)));
e.Graphics.Transform = m;
e.Graphics.FillRectangle(new SolidBrush(c), r);
e.Graphics.ResetTransform();
}
e.Graphics.FillRectangle(new SolidBrush(c), functions.ZoomRectangle(Annotations.Items[i].Box, picZoom, true));
}
The ZoomRectangle function scales the rectangle based on the Zoom level of the picturebox and the size of the image within the PictureBox. The rectangle rotate, just not in the right position.
When I rotate the image in my picturebox, how would I rotate my filled rectangle to maintain the exact same relative position on the picturebox?