c# – 使用Magick.NET创建多页TIFF

我正在使用Magick.NET并尝试创建multipage-TIFF文件.我的输入是PDF文件.但是将结果写入MemoryStream或将其作为字节数组导致错误:

iisexpress.exe: Error flushing data before directory write. `TIFFWriteDirectorySec’ @ error/tiff.c/TIFFErrors/551

但是当我将结果写入硬盘上的文件时,没有错误,文件也没问题.

这是我的代码:

var outputStream = new MemoryStream();
using (var inputPdf = new MagickImageCollection())
{
    inputPdf.Read(rawData, settings);

    using (var tif = new MagickImageCollection())
    {
        foreach (var pdf in inputPdf)
        {
            pdf.Depth = 8;
            pdf.Format = MagickFormat.Tif;
            tif.Add(pdf);
        }

        if (debug)
        {
            // Writing the data to a file is successful!
            tif.Write(pathImage);
        }

        // But writing it to a stream results in the error!
        //tif.Write(outputStream);

        // Same as getting the data as byte-array!
        var outputData = tif.ToByteArray(MagickFormat.Tif);
        outputStream.Write(outputData, 0, outputData.Length);
    }
}

解决方法:

解决了.

解决方案是设置压缩:

pdf.CompressionMethod = CompressionMethod.JPEG;

谁知道为什么?

上一篇:如何在python中将图像转换为16bit zip(deflate)压缩TIF?


下一篇:jqGrid方法整理