How to check corrupted TIFF images in C #?

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

+5
source share
4 answers

Please check out the free LibTiff.NET program. It has a function to check if each page in the TIF file is corrupted or not. Even partial damage is also not a problem.

http://bitmiracle.com/libtiff/

thanks

+4
source

Many tiff files will not open in standard GDI + .NET. That is, if you are running Windows XP. Window 7 is much better. Thus, any file that is not supported by GDI + (for example, fax, 16-bit grayscale, 48bpp RGB, tiled tiff, piramidical tiled tiff, etc.) will then be considered as β€œdamaged”. And not only that, everything that leads to a raster image on several 100 MB in a 32-bit system will also cause an exception in memory.

If your goal is to support as much of the TIFF standard as possible, please start with LibTiff (derivatives). I used LibTiff.NET from BitMiracle (LGPL), which worked fine for me. See My Other Posts

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

Regarding the TIFF specification suggested in other answers: of course, this gives you bit level control. But in my experience, you don’t have to go so low to have good TIFF support. The format is so universal that you will need a huge amount of time to start support from scratch.

+3
source

It will only be damaged in the sense that the framework methods cannot open it.

There are several types of TIFF that the structure cannot open - (In my case, I cannot remember the exact one, I think it was one of the types of FAX ...)

This may be enough for you if you just use the framework for image management. In the end, I cannot open it, you cannot use it ...

ImageMagic - can give you more options here

+2
source

Without looking at tiff, it can be difficult to see if it is damaged visually, but if you have problems processing the image, just create a function that performs a basic test for this type of processing and handles the error?

0
source

Source: https://habr.com/ru/post/905888/


All Articles