Scaling / stretching the image at the current position of the mouse?

Q: How can I implement scaling of the current mouse position over an image, something like scaling on Google Maps?

I am developing a simple GIS / map engine as my dissertation. The application is designed in such a way that maps are loaded into the tabs of a slightly modified tabcontrol.

Cards are standard digital images in JPEG or PNG format, and most of them have very high resolution (2000x2000px and higher).

They are loaded into graphic boxes, which are added as tab sub-elements. I implemented a simple scaling method as a button click event that only zooms in on the center of the image / image.

What I would like to do is implement the scaling of the mousewheel event so that the image is enlarged by the current mouse position inside the image window.

The code for scaling currently looks like this:

            timesZoomed += 1;
            zoomRatio += 0.1f;
            pbxMapa.Width = pbxMapa.Width * zoomRatio;
            pbxMapa.Height = pbxMapa.Height * zoomRatio;
            pbxMapa.Location = new Point((this.Width / 2) - (pbxMapa.Width / 2), this.Height / 2) - (pbxMapa.Height / 2));
  • The default value of "zoomRatio" is 1, and it increases to 0.6f.
  • The argument "timesZoomed" is 0 by default; it reaches 6.
  • "pbxMapa" is a window with a loaded map image. "ImageSizeMode" for the image window is set to "Zoom", but the image window size is set to the full size of the loaded map image.

In addition, I experimented with this simple scaling code. The calculation is somewhat effective, but still it has a fairly bias when scaling / multiplying with a large ratio:

                pbxMapa.Location = new Point(pbxMapa.Location.X + (int)((pbxMapa.Location.X * zoomRatio - mouseXPbx) / 8), pbxMapa.Location.Y + (int)((pbxMapa.Location.Y * zoomRatio - mouseYPbx) / 8));
  • "mouseXPbx" "mouseYPbx" "pbxMapa". 8 .

, .

+3
2

pictureBox

pictureBox1.Width = (int)(pictureBox1.Width * zoomratio );
pictureBox1.Height = (int)(pictureBox1.Height * zoomratio );                
pictureBox1.Top = (int)(e.Y - zoomratio * (e.Y - pictureBox1.Top));
pictureBox1.Left = (int)(e.X - zoomratio * (e.X - pictureBox1.Left));
+4

. , , .

pbxMapa.Location = new Point(pbxMapa.Location.X + (int)(((pbxMapa.Location.X - mouseXPbx) / 10) * zoomRatio), pbxMapa.Location.Y + (int)(((pbxMapa.Location.Y - mouseYPbx) / 10) * zoomRatio));
0

All Articles