문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top