tags:

views:

309

answers:

6

Hi Everyone,

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?

+2  A: 

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

Adrian
A: 

You can always read the TIFF specifications and implement your own TIFF-validation mechanism.

M.A. Hanin
Have you read the TIFF specification? It would take years to implement a validation method. Stand on the shoulders of giants and use already implemented/available code.
Adrian
A: 

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?

Mark Redman
assuming you dont want to validate the actual file contents to its strict specification...
Mark Redman
+2  A: 

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.

Adriaan
A: 

Hi all,

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

Michael Foo
A: 

Hi Micheal,

Can you show us how the checking for corrupted TIF can be done using http://bitmiracle.com/libtiff/?

Best Regards, Elaine Tam

elaine