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.AllowVitalTagChanges = true;
//Try to find one.
TiffTag photometric = file.Images.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.