Question

The following (simplified) C# code creates a multi page tiff file:

using System.Windows.Media.Imaging;
var tiffBitmapEncoder = new TiffBitmapEncoder();
using (var ms = new MemoryStream())
{
    tiffBitmapEncoder.Compression = TiffCompressOption.Zip;
    foreach (.....)
    {
        //Generate the image to add to tiff
        .....
        var bitmapSource = new BitmapImage(new Uri(.....));
        tiffBitmapEncoder.Frames.Add(BitmapFrame.Create(bitmapSource));
    }
    tiffBitmapEncoder.Save(ms);
}

The compression seems to be done on each frame/bitmap individually. Therefore the file size grows linearly by the number of frames/bitmaps.

Is there a way to compress the tiff file as a whole?

Was it helpful?

Solution

Is there a way to compress the tiff file as a whole?

Short answer: No. TIFF images are always compressed per image/tile/strip.

Small print: It's possible for JPEG-encoded TIFF files to share tables, this could potentially perform better than linear growth, but I don't think this is what you are looking for.

You can of course create an uncompressed TIFF file, and compress it all using gz, zip or similar tools. However, it won't be a TIFF file any more. And I doubt it will compress better than TIFF with ZIP/Deflate + Predictor.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top