Rajendra Tripathy
Rajendra Tripathy

Reputation: 942

CompressionType for an Image

private static int GetCompressionType(Image image)
{
    // The zero-based index of the first occurrence within the entire array, if found; otherwise, –1.

    int compressionTagIndex = Array.IndexOf(image.PropertyIdList, 0x103);
    PropertyItem compressionTag = image.PropertyItems[compressionTagIndex];
    return BitConverter.ToInt16(compressionTag.Value, 0);
}

Hello Programers. I wrote a program where i can rotate an Image (any kind of image) based on User input. Concern is when I rotate the tiff image, its actually rotate as per user input but i loose the compression, so used the above method (googled it).. And now I have some doubts on this..

  1. Why the specific 0x103 ???
  2. Is this method is specific to Tiff ?
  3. For JPG, JPEG or BMP does I need to look into the compression type?

Upvotes: 2

Views: 977

Answers (1)

plinth
plinth

Reputation: 49189

The TIFF file format is also known as Tagged Image File Format. There are collections of tags and values that describe the image and how it is stored within the file.

In this case, there is a tag which describes the image compression, which happens to be tag value 0x103. Now, that's just the tag. The value describes the actual compression type, the most common of which are:

  1. No compression
  2. CCITT Huffman
  3. CCITT Group 3
  4. CCITT Group 4
  5. LZW
  6. Old style JPEG (DO NOT USE THIS)
  7. New style JPEG
  8. Flate

Upvotes: 5

Related Questions