C# 使用Magick.NET创建多页TIFF

C# 使用Magick.NET创建多页TIFF,c#,tiff,magick.net,C#,Tiff,Magick.net,我正在使用Magick.NET并尝试创建多页TIFF文件。我的输入是一个PDF文件。但将结果写入MemoryStream或将其作为字节数组获取会导致错误: iisexpress.exe:写入目录前刷新数据时出错`TIFFWriteDirectorySec'@error/tiff.c/TIFFErrors/551 但是,当我将结果写入硬盘上的文件时,没有错误,文件也没有问题 这是我的密码: var outputStream = new MemoryStream(); using (var inpu

我正在使用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.CompressionMethod = CompressionMethod.JPEG;

有人知道为什么吗?

你能给你正在使用的PDF添加一个链接吗?