I have tiff file with 7000 pages, each image is 300 x 309 pixels. The entire tiff file is 2.5GB. I was able to read all the images and display in my WPF app. But when I try to create a new tiff file which is a subset of images it says 'The image data generated an overflow during processing'.
This only happens after page 5789 for some reason. If I were to write all the pages from 1 to 5788 it works. But If I were to start from 5789 it just throws this exception.
I tried checking the display settings from this answer. But it is default everywhere for me.
My code to read and write the tiff files (.Net framework 4.7.1):
Stream imageStreamSource = new FileStream(tiffFile, FileMode.Open, FileAccess.Read, FileShare.Read);
TiffBitmapDecoder decoder = new TiffBitmapDecoder(imageStreamSource, BitmapCreateOptions.None, BitmapCacheOption.Default);
var images = decoder.Frames.Cast<BitmapSource>().ToList().GetRange(5000, 1000);
using (var fs = new FileStream(saveTiffFile, FileMode.Create))
{
BitmapEncoder encoder = new TiffBitmapEncoder();
for (int i = 0; i < images.Count; i++)
{
encoder.Frames.Add(BitmapFrame.Create(images[i]));
}
encoder.Save(fs);
}
gcAllowVeryLargeObjectsonly affects the size of arrays, as in number of bytes. Not the item limit. Ofc, for byte arrays, the number of bytes and number of items is the same, so the lower limit applies. As Blindy mentions, your best bet is probably to use a different encoder.