hey guys!
So i am currently adding a mapviewing component to my application which uses a picture box and this code i found from here: rotate-a-picture-in-c
I would like to change up this function to allow the user to zoom to a point probably like :
private void DisplayImage(Point location, bool zoomIn)
with location being the location within the picturebox where the user will be zooming from.
I tried messing arround with gr.ScaleTransform with no success.
any help would be greatly appreciated!
// Display the image at the current rotation and scale.
private void DisplayImage()
{
if (OriginalImage == null) return;
RotatedImage = null;
picRotatedImage.Visible = false;
float angle;
if (!float.TryParse(txtAngle.Text, out angle)) return;
// Find the size of the image's rotated bounding box.
Matrix rotation = new Matrix();
rotation.Rotate(angle);
int old_wid = OriginalImage.Width;
int old_hgt = OriginalImage.Height;
PointF[] points =
{
new PointF(0, 0),
new PointF(old_wid, 0),
new PointF(0, old_hgt),
new PointF(old_wid, old_hgt),
};
rotation.TransformPoints(points);
float[] xs =
{ points[0].X, points[1].X, points[2].X, points[3].X };
float[] ys =
{ points[0].Y, points[1].Y, points[2].Y, points[3].Y };
int new_wid = (int)(xs.Max() - xs.Min());
int new_hgt = (int)(ys.Max() - ys.Min());
// Make the rotated image.
RotatedImage = new Bitmap(new_wid, new_hgt);
using (Graphics gr = Graphics.FromImage(RotatedImage))
{
gr.TranslateTransform(-old_wid / 2, -old_hgt / 2,
MatrixOrder.Append);
gr.RotateTransform(angle, MatrixOrder.Append);
gr.TranslateTransform(new_wid / 2, new_hgt / 2,
MatrixOrder.Append);
RectangleF source_rect = new RectangleF(0, 0,
OriginalImage.Width, OriginalImage.Height);
PointF[] dest_points =
{
new PointF(0, 0),
new PointF(OriginalImage.Width, 0),
new PointF(0, OriginalImage.Height),
};
gr.DrawImage(OriginalImage, dest_points, source_rect,
GraphicsUnit.Pixel);
}
// Scale the output PictureBox.
SetPictureBoxSize();
// Display the result.
picRotatedImage.Image = RotatedImage;
picRotatedImage.Visible = true;
}
