Home : TIFF : Working around the "PhotometricInterpretation tag missing" error
Q10390 - HOWTO: Working around the "PhotometricInterpretation tag missing" error

You may find that you have a Tiff that when opened throws an error with the message "PhotometricInterpretation tag missing". The photometric interpretation tag is tells the software displaying the Tiff what format to expect the image data. Formats like black and white, color or paletted.

While we are going to go over how to resolve this issue in some files, a missing photometric interpretation tag is a very serious violation of the Tiff specification. There is a fair chance that the software that has left this tag out has violated the spec somewhere else as well, or that the file has been corrupted.

If you have a one-off file that throws this error, it may be simplest to fix it with a bit of manual code. We're going to use the TiffFile class as it lets us open/modify the Tiff without producing an image from it.

using (Stream existingTiff = File.OpenRead(@"Existing.tiff"))

    TiffFile file = new TiffFile();

//PhotometricInterpretation is a vital tag.
    file.Images[0].AllowVitalTagChanges = true;

//Try to find one.
    TiffTag photometric = file.Images[0].Tags.LookupTag(TiffTagID.PhotometricInterpretation);

    if (photometric == null)
//Add a tag, set MinIsWhite (most common.) Look at the 
//PhotometricInterpretation definition for other values. 
        photometric = new TiffTag(TiffTagID.PhotometricInterpretation, 0, TiffTagDataType.Short); 

        using(Stream streamOut = File.OpenWrite(@"Fixed.tiff")) 
//Save as a new file.


That will fix your one-off files easily enough, but what if you need to view images from them and cannot modify the originals? Or you have many thousands of them? Well, this is where the extensibility of the Atalasoft DotImage toolkit comes in.

You can extend the TiffDecoder class and add this logic in to the Read and GetImageInfo methods to automatically fix the missing tag without having to alter the rest of your application. There is an completed example of this attached to this KB.

Related Articles
No Related Articles Available.

Article Attachments

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?


Tell us why you rated the content this way. (optional)
Approved Comments...
No user comments available for this article.

Powered By InstantKB.NET v1.3
Copyright © 2002, 2020. InstantASP Ltd. All Rights Reserved