Question

My application has to handle TIFF files that are stored in a MemoryStream, but LibTiff.Net always returns null for the field values.

        MemoryStream ms = new MemoryStream();
        FileStream fs = new FileStream("testfile.tif", FileMode.Open);
        fs.CopyTo(ms);

        //It seems (memory) streams have to be opened in write mode, "r" always returns <null>
        Tiff tiff = Tiff.ClientOpen("someArbitraryName", "w", ms, new TiffStream());

        FieldValue[] imageHeight = tif.GetField(TiffTag.IMAGELENGTH);

Opening the file directly for reading using Tiff.Open works fine.

Is this a bug in the LibTiff.Net library or am I missing something?

Was it helpful?

Solution

Bit Miracle support team provided me with the solution:

Tiff.ClientOpen reads data from the current position of the stream.

    MemoryStream ms = new MemoryStream();
    FileStream fs = new FileStream("testfile.tif", FileMode.Open);
    fs.CopyTo(ms);

    ms.Position = 0;

    Tiff tiff = Tiff.ClientOpen("someArbitraryName", "r", ms, new TiffStream());

    FieldValue[] imageHeight = tif.GetField(TiffTag.IMAGELENGTH);

This fixes the problem.

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