如何确定屏幕上的实际尺寸?
在具有缩放功能的 wpf 控件中,我根据 MouseWheelEventArgs 计算如何缩放绘图画布以实现缩放效果。
Point mouse = e.GetPosition(myCanvas);
Matrix m = myCanvas.RenderTransform.Value;
if (e.Delta > 0)
{
f = 1.1;
}
else
{
f = 1.0 / 1.1;
}
m.ScaleAtPrepend(f, f, mouse.X, mouse.Y);
myCanvas.RenderTransform = new MatrixTransform(m);
我想知道画布上其中一个圆圈的实际大小。然而,宽度、实际宽度等在放大和缩小时保持不变 (16.0)。您如何确定(计算?)用户在屏幕上实际看到的圆圈的大小?
In a wpf control with zoom functionality I calculate from the MouseWheelEventArgs how to scale the drawing canvas to implement the zoom effect.
Point mouse = e.GetPosition(myCanvas);
Matrix m = myCanvas.RenderTransform.Value;
if (e.Delta > 0)
{
f = 1.1;
}
else
{
f = 1.0 / 1.1;
}
m.ScaleAtPrepend(f, f, mouse.X, mouse.Y);
myCanvas.RenderTransform = new MatrixTransform(m);
I would like to know the actual size of one of the circles on the canvas. However Width, ActualWidth and such stay the same while zooming in and out (16.0). How would you determine (calculate?) the size of the circle that a user actually sees on his or her screen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MatrixTransform 有一个方法 TransformBounds 来实现此目的。你给它提供图像的原始边界框(我认为在你的情况下 0,0,宽度,高度就可以),它会返回你得到的边界框。
MatrixTransform has a method TransformBounds for this. You feed it with original bounding box of the image (I think in your case 0,0,width,height will do) and it will return you its resulting bounding box.