缩放至视口中心
我目前正在尝试编写一个可缩放的 UserControl 并且我已经 目前正在效仿鲍威尔的榜样 在 https://web.archive.org/web /20141229192708/http://bobpowell.net/zoompicbox.aspx,但是,我正在尝试 实现的是缩放到控件的中心点,而不是 左上角。
有人对此有经验/想法吗?
I'm currently trying to write a zoomable UserControl and I've
currently followed Bob Powell's example
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将控件的值向中心偏移,应用缩放变换,然后向后偏移。
尝试以下算法来计算新的左上角:
如果控件为 100,100,则将产生缩放系数 2:
缩放系数为 0.5:
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:
If the control is 100,100 a zoom factor of 2 will produce:
With a zoom factor of 0.5: