Home : Error in tiff codec: PhotometricInterpretation tag missing
Q10277 - ERRMSG: Error in tiff codec: PhotometricInterpretation tag missing

When the PhotometricInterpretation tag is missing from a document, DotImage will refuse to render the image because it is in direct violation to the tiff specification. In other programs (most notibly Windows Picture and Fax Viewer, included in XP), tiff files without this tag may open. This is because they are making the assumption that the file is MinIsWhite interpretation. Here is a snippit of code that will allow modulation/addition of this tag in corrupt images:

 

C#

TiffFile tiff = new TiffFile();

OpenFileDialog open = new OpenFileDialog();

open.ShowDialog();

using (Stream s = open.OpenFile())

{

     tiff.Read(s);

     foreach (TiffDirectory frame in tiff.Images)

     {

         try

         {

            int i = (int)(frame.Tags.LookupTag(TiffTagID.PhotometricInterpretation).Data);

         }

         catch (Exception ex)

         {

            FixTag(frame);

         }

      }

      tiff.Save("out.tif");

}

 

private void FixTag(TiffDirectory frame)

{

   frame.Tags.Add(new TiffTag(TiffTagID.PhotometricInterpretation, 0)); //0 is MinIsWhite many programs assume this regardless of its appearance or not and is not a correct interaction defined by the tiff specification.

}

  

VB.NET

Dim tiff As New TiffFile()

Dim open As New OpenFileDialog()

open.ShowDialog()

Using s As Stream = open.OpenFile()

    tiff.Read(s)

    For Each frame As TiffDirectory In tiff.Images

        Try

            Dim i As Integer = CInt((frame.Tags.LookupTag(TiffTagID.PhotometricInterpretation).Data))

        Catch ex As Exception

            FixTag(frame)

        End Try

    Next

    tiff.Save("out.tif")

End Using

 

Private Sub FixTag(ByVal frame As TiffDirectory)

        '0 is MinIsWhite many programs assume this regardless of its appearance or not and is not a correct interaction defined by the tiff specification.

    frame.Tags.Add(New TiffTag(TiffTagID.PhotometricInterpretation, 0))

End Sub

 

Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

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

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
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, 2019. InstantASP Ltd. All Rights Reserved