2011-03-25 76 views
3

我使用FreeImage处理多页TIFF文件,并在某些时候我有一个TIFF页面,在FIBITMAP,我需要知道它的压缩。任何想法如何做到这一点?如何找出FreeImage中TIFF图像的压缩?

+0

我有同样的问题!如果你会发现如何做到这一点,请在这里回答! – ieaglle 2011-05-01 14:42:59

回答

1

的FreeImage没有内置的功能,以显示TIFF文件压缩方案,但是你可以使用的Exif元数据来找出答案(DIB是当地FIBITMAP变量,这是C#代码):

public string GetCompressionName() 
    { 
     long _compression; 

     if (dib.IsNull) 
      throw new Exception("dib is empty - image haven't been loaded!"); 

     //Searching tag in metadata. 
     ImageMetadata iMetadata = new ImageMetadata(dib); 

     foreach (MetadataModel metadataModel in iMetadata) 
     { 
      if (metadataModel.ToString() == "FIMD_EXIF_MAIN") 
      { 
       try 
       { long.TryParse(metadataModel.GetTag("Compression").ToString(), out _compression); } 
       catch 
       { return "Unknown"; } 


       if (CompressType.ContainsKey(_compression)) 
       { 
        string _compressionName; 
        CompressType.TryGetValue(_compression, out _compressionName); 

        if (_compressionName != null) 
        { 
         return _compressionName; 
        } 
       } 
      } 
     } 

     return "Unknown"; 
    } 

Dictionary<long, string> CompressType = new Dictionary<long, string>() 
     { 
      {1, "Uncompressed" } , 
      {2, "CCITT modified Huffman RLE"}, 
      {32773, "PackBits"}, 
      {3, "CCITT3"}, 
      {4, "CCITT4"}, 
      {5, "LZW"}, 
      {6, "JPEG_old"}, 
      {7, "JPEG_new"}, 
      {32946, "DeflatePKZIP"}, 
      {8, "DeflateAdobe"}, 
      {9, "JBIG_85"}, 
      {10, "JBIG_43"}, 
      {11, "JPEG"}, 
      {12, "JPEG"}, 
      {32766, "RLE_NeXT"}, 
      {32809, "RLE_ThunderScan"}, 
      {32895, "RasterPadding"}, 
      {32896, "RLE_LW"}, 
      {32897, "RLE_HC"}, 
      {32947, "RLE_BL"}, 
      {34661, "JBIG"}, 
      {34713, "Nikon_NEF"}, 
      {34712,"JPEG2000"} 
     };