我正在使用Magick.NET并尝试创建multipage-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);
}
}
答案 0 :(得分:3)
解决。
解决方案是设置压缩:
pdf.CompressionMethod = CompressionMethod.JPEG;
有谁知道为什么?