Zoom to the center of view port
I'm currently trying to write a zoomable UserControl and I've currently followed Bob Powell's exam开发者_开发技巧ple at https://web.archive.org/web/20141229192708/http://bobpowell.net/zoompicbox.aspx, however, what I'm trying to achieve is zooming to the center point of the control, not the top left corner.
Is anybody having experience/idea on this?
You need to offset the values of the control by the centre, apply the scale transform and then offset back.
Try the following algorithm to calculate the new top left:
(-old_centre * factor) + old_centre
If the control is 100,100 a zoom factor of 2 will produce:
((-50, -50) * 2) + (50, 50) = (-100, -100) + (50, 50) = (-50, -50)
With a zoom factor of 0.5:
((-50, -50) * 0.5) + (50, 50) = (-25, -25) + (50, 50) = (25, 25)
精彩评论