在 WPF 中高效显示和缩放/平移大图像

发布于 2024-11-01 10:57:52 字数 648 浏览 0 评论 0原文

我目前正在开发一个应用程序,需要显示 8800x6800 或更大的大型工程图。要求规定用户应该能够平移和缩放图像。理想情况下,他们还希望能够对图像进行注释。如果您查看 Windows 照片查看器,您将看到我想要模拟的性能和功能,减去注释部分。

到目前为止,我已经尝试了几种不同的方法来显示图像,但似乎没有一种方法能够提供我想要的性能。它们要么占用大量内存,要么速度很慢。这些是我采取的方法:

  • ViewboxImage 作为子项。内存使用情况还可以,但重新调整 Viewbox 的大小很慢。因此,我还没有尝试过使用这种方法进行缩放/平移。
  • InkCanvasImage 设置为背景或子项。使用这种方法,通过 ScaleTransform 和 TranslateTransform 进行缩放/平移看起来一般,但内存使用量可能会增加到 450-600 MB 范围内。

这是我第一次尝试使用 .NET/WPF 进行图像处理,我对这个主题的了解相当有限。处理大图像(尤其是 WPF)的最佳实践有哪些?我读过平铺图像(如深度缩放)可以提供帮助,但不确定如何做到这一点,或者这是否是我的情况下的最佳主意。您知道有什么资源可以帮助我更好地理解这一点吗?

I'm currently working on an application with the need to display large engineering drawings that can be 8800x6800 or larger. The requirements state that the user should be able to pan and zoom the image. Ideally, they'd like to be able to annotate the images as well. If you look at the Windows Photo Viewer, you'll see the performance and features I'm looking to emulate, minus the annotation part.

So far, I've tried a couple different approaches for displaying the images and none seem to offer the performance that I'm looking for. Either they take up a lot of memory or they're slow. These are the approaches I've taken:

  • Viewbox with the Image as a child. Memory usage is OK, but re-sizing the Viewbox is slow. I haven't tried zooming/panning with this approach yet because of that.
  • InkCanvas with the Image set either as the background or as a child. With this approach zooming/panning by way of ScaleTransform and TranslateTransform seemed so-so, but memory usage could be up in the 450-600 MB range.

This is my first foray into image manipulation with .NET/WPF and my knowledge on the subject is fairly limited. What are some best-practices for dealing with large images, especially with WPF? I've read that tiling the image (like deep zoom) can help, but was unsure on how to do this or if it's the best idea in my situation. Do you know of any resources that might help me understand this better?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

计㈡愣 2024-11-08 10:57:52

如果您所说的“平铺”是将图像分割成单独的部分并一次仅显示一小部分以提高性能,则这称为“虚拟化”。

Microsoft 有一个关于虚拟化项目的优秀博客,甚至提供了 VirtualCanvas 的参考实现,您可以将其用作虚拟化控件的起点。

链接如下: https://learn.microsoft.com /en-us/archive/blogs/jgoldb/virtualized-wpf-canvas

请注意,此博客包括缩放和缩放作为讨论的一部分,以及关于平滑滚动和抢先加载图块以获得最佳效果的讨论用户界面响应能力。

By "tiling" if you mean splitting the image up into separate pieces and only displaying a small subset at once to improve performance, this would be called "virtualisation".

Microsoft has an excellent blog about virtualising items and even provides a reference implementation of a VirtualCanvas which you can use as the starting point for a virtualised control.

Link here: https://learn.microsoft.com/en-us/archive/blogs/jgoldb/virtualized-wpf-canvas

Note that this blog includes zoom and scale as part of the discussion as well as a discussion about smooth scrolling and pre-emptive loading of tiles for best UI responsiveness.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文