Mouse-centric scaling of images like maps

Source: Internet
Author: User

Zoom to the center of the mouse, just like when using Baidu maps. This approach is more consistent with people's thinking inertia than the general image center-centric scaling.

Found on the internet did not find ready-made, their own research for half a day, around to go around, dizzy. Later, the help of a group of friends to solve the problem.

Here is the code that is rewritten by the method provided by the cyber-Decepticons brothers:

Procedure Tform1.zoom (I:single); var  neww, Newh:integer;  Newx, Newy, SX, Sy:integer;  A, B:double;begin  fscale: = Fscale + Round (Fscale * I);  NEWW: = Trunc (IMGW * (fscale/1000));  NEWH: = Trunc (IMGH * (fscale/1000));  SX: = Image1.left;  SY: = image1.top;  if (Neww < clientwidth) and (Newh < clientheight) THEN begin    //image is smaller than window, center display    newx: = (CLIENTWIDTH-NEWW) s HR 1;    Newy: = (CLIENTHEIGHT-NEWH) shr 1;  End ELSE begin    //window does not display when    //newx: = SX;    Newy: = SY;    GetCursorPos (Mouse);    Mouse: = ScreenToClient (Mouse);    Mouse: = Image1.clienttoparent (Mouse);    A: = (MOUSE.X-SX)/image1.width;    B: = (mouse.y-sy)/image1.height;    NEWX: = Sx-round ((neww-image1.width) * A);    Newy: = Sy-round ((newh-image1.height) * B);  End;  Image1.setbounds (Newx, Newy, NEWW, NEWH); end;

As you can see from the code above, first get the coordinates of the mouse in the image display client area, and then:
The relative position of the mouse before zooming X = (mouse coordinates. X-the image is scaled before the coordinates. Left)/image width;
The relative position of the mouse before zooming Y = (mouse coordinates. Y-the image is scaled before the coordinates. TOP)/Image height;

The relative position of the mouse before zooming, then using the coordinates before zooming-multiplied by the difference of the size of the scaled image (for example, the original size is a, the new size is B, the difference is b-a).

Full demo Download: Http://pan.baidu.com/s/1eQovAsa

Http://www.cnblogs.com/yangyxd/articles/3984919.html

Mouse-centric scaling of images like maps

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.