Question

I am trying to use a LibTiff.Net library and rewriting a merge tool TiffCP api to use memory streams.

This library has a Tiff class and by passing a stream to this class, it can merge tiff images into this stream.

For testing, I passed on a Filestream and I got what i wanted - it merged and I was able to see multipage tif.

But when I pass a MemoryStream, I am able to verify that the page data is being added to the stream as I loop through but when I write it to the file at the end, I could see only 1st page.

var mso = new MemoryStream();
var fso = new FileStream(@"C:\test\ttest.tif",FileMode.OpenOrCreate); //This works
using (Tiff outImage = Tiff.ClientOpen("custom", "w", mso, tso))
{
 //...
 //..
 System.Drawing.Image tiffImg = System.Drawing.Image.FromStream(mso, true);
 tiffImg.Save(@"C:\test\test2.tiff", System.Drawing.Imaging.ImageFormat.Tiff);
 tiffImg.Dispose();
 //..
 //..
}

P.S: I need it in memorystream because, of some folder permissions on servers + vendor API reasons.

Was it helpful?

Solution

You probably using the memory stream before data is actually written into the stream.

Please use Tiff.Flush() method before accessing data in the memory stream. And please make sure you call Tiff.WriteDirectory() method for each page you create.

EDIT:

Please also take a look at Bob Powell's article on Generating Multi-Page TIFF files. The article shows how to use EncoderParameters to actually generate a multipage TIFF.

Using

tiffImg.Save(@"C:\test\test2.tiff", System.Drawing.Imaging.ImageFormat.Tiff);

you are probably save only first frame.

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