如何在 C# 中检查损坏的 TIFF 图像?

发布于 2024-08-28 08:37:07 字数 118 浏览 3 评论 0原文

我搜索了如何检查 TIFF 文件是否损坏。大多数人建议将 Image.FromFile 函数包装在 try 块中。如果它抛出 OutOfMemoryException,则它已损坏。有人用过这个吗?有效果吗?还有其他选择吗?

I searched on how to check if a TIFF file is corrupt or not. Most suggests wrapping the Image.FromFile function in a try block. If it throws an OutOfMemoryException, its corrupt. Has anyone used this? Is it effective? Any alternatives?

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

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

发布评论

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

评论(4

安静 2024-09-04 08:37:07

请查看名为 LibTiff .NET 的免费软件。它具有检查 TIF 文件中的每个页面是否损坏的功能。即使部分损坏也没有问题

http://bitmiracle.com/libtiff/

谢谢

Please check out the freeware called LibTiff .NET. It has the function to check if every page in a TIF file is corrupted or not. Even partially corrupt also no problem

http://bitmiracle.com/libtiff/

Thanks

一梦等七年七年为一梦 2024-09-04 08:37:07

许多 tiff 文件无法在标准 GDI+ .NET 中打开。也就是说,如果您运行的是 Windows XP。 Window 7 好多了。因此,任何不受 GDI+ 支持的文件(即传真、16 位灰度、48bpp RGB、平铺 tiff、piramidical 平铺 tiff 等)都会被视为“损坏”。不仅如此,在 32 位系统上任何导致位图超过几百 MB 的情况也会导致内存不足异常。

如果您的目标是尽可能支持 TIFF 标准,请从 LibTiff(衍生版本)开始。我使用了 BitMiracle (LGPL) 的 LibTiff.NET,它对我来说效果很好。请参阅我的其他帖子

许多 TIFF 实用程序也基于LibTIFF,其中一些移植到C#.NET。如果您想验证 TIFF,这将是我的建议。

至于其他回复中建议的 TIFF 规范:当然,这为您提供了位级控制。但根据我的经验,您不需要那么低就能获得良好的 TIFF 支持。该格式用途广泛,从头开始提供支持将花费您大量的时间。

Many tiff files won't open in the standard GDI+ .NET. That is, if you're running on Windows XP. Window 7 is much better. So any file which is not supported by GDI+ (i.e. fax, 16 bit gray scale, 48bpp RGB, tiled tiff, piramidical tiled tiff etc.) are then seen as 'corrupt'. And not just that, anything resulting in a bitmap over a few 100 MByte on a 32-bit system will also cause an out-of-memory exception.

If your goal is to support as much as possible of the TIFF standard, please start from LibTiff (derivates). I've used LibTiff.NET from BitMiracle (LGPL), which worked well for me. Please see my other posts

Many of the TIFF utilities are also based on LibTIFF, some of them are ported to C#.NET. This would be my suggestion if you want to validate the TIFF.

As for the TIFF specification suggested in other replies: of course this gives you bit-level control. But to my experience you won't need to go that low to have good TIFF support. The format is so versatile that it will cost you an enormous amount of time to start support from scratch.

凉月流沐 2024-09-04 08:37:07

它只会在框架方法无法打开它的意义上被损坏。

有一些 TIFF 类型是框架无法打开的 -(在我的情况下,我不记得确切的类型,认为它是 FAX 类型之一......)

如果您只是想使用操作图像的框架。毕竟我你无法打开它,你无法使用它......

ImageMagic - 可能会在这里给你更多的范围

It will only be corrupt in the sense that the frameworks methods cant open it.

There are some TIFF types that the framework cannot open -( In my case I cant remember the exact one, think it was one of the FAX type ones...)

That may be enough for you, if you are just looking a using the framework to manipulate images. After all I you cant open it, you cant use it...

ImageMagic - may give you more scope here

少女情怀诗 2024-09-04 08:37:07

如果不查看 tiff,可能很难从视觉角度看出它是否损坏,但如果您在处理图像时遇到问题,只需创建一个函数来对此类处理进行基本测试并处理错误?

Without looking at the tiff, it may be difficult to see if its corrupt from a visual perspective, but if you have issues with processing an image, just create a function that does a basic test for this type of processing and handle the error?

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