Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check for corrupt TIFF images in C#?

Tags:

c#

image

tiff

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?

like image 560
Jojo Avatar asked Apr 12 '10 11:04

Jojo


People also ask

How do I view the data of a TIFF file?

For Windows:Highlight the file you want to open. Double-click. The TIFF file should open in Windows Photo Viewer.

How do you check if the file is corrupted in C#?

The best way to determine that the file is corrupted is to use specialized libraries of that type like PDF file libraries. There are lots of both free and commercial of such libraries for . NET. You may simply try to load file with one of such libraries.


2 Answers

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

like image 200
Michael Foo Avatar answered Oct 05 '22 06:10

Michael Foo


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.

like image 26
Adriaan Avatar answered Oct 05 '22 08:10

Adriaan