WPF 在缩放大型场景时的性能
我有一个全屏应用程序,我希望能够放大某些区域。
我的代码工作正常,但我注意到,当我靠近时,放大动画(它对父级上的 ScaleTransform.ScaleX 和 ScaleTransform.ScaleY 属性进行动画处理) canvas)开始稍微下降,帧速率受到影响。
我没有使用任何位图效果或任何东西,理想情况下我希望我的场景变得比目前更复杂。
场景相当大,1980x1024,这是要求,无法更改。
当前的布局是这样的:
<Canvas x:name="LayoutRoot">
<Canvas x:Name="ContainerCanvas">
<local:MyControl x:Name="c1" />
<!-- numerous or ther controls and elements that compose the scene -->
</Canvas>
</Canvas>
放大的代码只是对 ContainerCanvas 的 RenderTransform 进行动画处理,然后缩放其子项以提供所需的效果。
但是,我想知道是否需要将 ContainerCanvas 换成 ViewBox 或类似的东西?我以前从未在 WPF 中真正使用过 ViewBox/Viewport 控件,它们可以在这里帮助我吗?
平滑缩放是客户的一个巨大要求,我必须解决这个问题。
欢迎所有想法
非常感谢
马克
I have a full screen app that I want to be able to zoom in on certain areas.
I have the code working fine, but I notice that when I get closer in, the zoom in animation (which animates the ScaleTransform.ScaleX
and ScaleTransform.ScaleY
properties on a Parent canvas) starts to jerk down a little and the frame rate suffers.
Im not using any BitmapEffects or anything, and ideally I would like my scene to get more complicated than it currently already is.
The scene is quite large, 1980x1024, this is a requirement and cannot be changed.
The current layout is like this:
<Canvas x:name="LayoutRoot">
<Canvas x:Name="ContainerCanvas">
<local:MyControl x:Name="c1" />
<!-- numerous or ther controls and elements that compose the scene -->
</Canvas>
</Canvas>
The code that zooms in just animates the RenderTransform
of the ContainerCanvas, which in tern, scales its children which gives the desired effect.
However, Im wondering if I need to swap out the ContainerCanvas for a ViewBox or something like that? Ive never really worked with ViewBox/Viewport controls before in WPF can they even help me out here?
Smooth zooming is a huge requirement of the client and I must get this resolved.
All ideas are welcome
Thanks a lot
Mark
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现双色调图像也存在类似的问题,需要进行缩放和平滑平移,但双色调图像需要抗锯齿才能使屏幕观看可接受。
显然,这种抗锯齿会导致性能问题。您是否使用过
RenderOptions.SetBitmapScalingMode()
来处理您正在显示的图像对象?如果是这样,您可能必须在缩放动画的速度/性能和渲染图像的质量之间进行权衡。
我想到过但还没有时间实现的一种可能的解决方案是在动画期间切换到低质量位图缩放模式,并在动画结束时切换回高质量。
I see a similar problem with bitonal images which need to be zoomed and smooth panned, but being bitonal need to be anti-aliased to make onscreen viewing acceptable.
Obviously this anti-aliasing can cause performance issues. Have you played around with the
RenderOptions.SetBitmapScalingMode()
for the image object your are displaying?If so you may have to trade off between the speed/performance of the zoom animation and the quality of the rendered image.
One possible solution I had thought of, but have not yet had time to implement, would be to switch into a low quality bitmap scaling mode during the animation, and switching back to high quality at the end of the animation.