开发者

Zoom to the center of view port

开发者 https://www.devze.com 2022-12-10 15:21 出处:网络
I\'m currently trying to write a zoomable UserControl andI\'ve currently followed Bob Powell\'s exam开发者_开发技巧ple

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)
0

精彩评论

暂无评论...
验证码 换一张
取 消