如何在 WPF 中处理巨大的 tif?
我有一个 8 位 tiff,即 14406x9606 像素,通过 BitmapImage 加载时会抛出 System.OutOfMemoryException。作为全深度位图,其大小约为 400 兆。有没有办法将图像分割成更易于管理的块?我尝试使用 DecodePixelHeight 以较低的分辨率加载它,这有效,但是每当缩放级别发生变化时我都需要重新加载。是否有任何成熟的工具可以在 WPF 中以不同的缩放级别处理真正的大图像?
I have an 8bit tiff thats 14406x9606 pixels that when loaded via BitmapImage throws a System.OutOfMemoryException. As a full depth bitmap its about 400 megs in size. Is there a way to partition the image into more manageable chunks? I've tried using DecodePixelHeight to load it at a lower resolution and this works, but then I need to reload whenever the zoom level changes. Are there any established tools for dealing with really large images in WPF at differing zoom levels?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有任何内置的东西可以直接处理这个问题。正如您所提到的,DecodePixelHeight 可能是框架本身的最佳选择。
但是,您可以使用GDAL 的 C# 包装器之类的东西。 GDAL 可处理非常大的 TIFF 文件,包括带有金字塔的文件,并允许您(非常快速)以不同的分辨率打开 TIFF,而无需将整个文件加载到内存中。这仍然需要在分辨率更改时刷新/重新加载,但其 TIFF 加载速度比框架的成像类快很多,因为它设计用于处理极大的图像。
There is nothing built-in that handles this directly.
DecodePixelHeight
, as you mentioned, is probably the best option in the framework itself.However, you could use something like the C# wrappers for GDAL. GDAL handles very large TIFF files, including ones with pyramids, and allow you to (very quickly) open up the TIFF at varied resolutions without loading the entire file into memory. This will still require a refresh/reload on resolution change, but the speed of their TIFF loading is quite a bit faster than the framework's imaging classes, as it's designed to handle extremely large imagery.
您可能想尝试 LibTiff.Net 库。它是用纯 C# 代码编写的,免费、开源(商业友好的 BSD 许可证)。
LibTiff.Net 可以处理最大 4 GB 的 TIFF 文件,并且可用于打开文件而无需解码所有样本。该库还支持多条带和平铺 TIFF 文件。
免责声明:我是图书馆的维护者之一。
You may want to try LibTiff.Net library. It's written in pure C# code, free, open source (commercial-friendly BSD license).
LibTiff.Net can handle TIFF files up to 4 GB in size and may be used to open files without decoding all the samples. The library also supports multi-strip and tiled TIFF files.
Disclaimer: I am one of the maintainers of the library.