使用Magick.NET创建多页TIFF

5
我正在使用Magick.NET尝试创建多页TIFF文件。我的输入是一个PDF文件。但是,将结果写入MemoryStream或以字节数组的形式获取结果会导致错误:
iisexpress.exe:在目录写入之前刷新数据时出错。`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文件的链接吗? - dlemstra
1个回答

3

已解决。

解决方案是设置压缩:

pdf.CompressionMethod = CompressionMethod.JPEG;

有人知道为什么吗?这与IT技术有关。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接