TiffBitmapDecoder decoder = new TiffBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
using (MemoryStream allFrameStream = new MemoryStream())
{
foreach (BitmapFrame frame in decoder.Frames)
{
using (MemoryStream ms= new MemoryStream())
{
JpegBitmapEncoder enc = new JpegBitmapEncoder();
enc.Frames.Add(BitmapFrame.Create(frame));
enc.Save(ms);
ms.CopyTo(allFrameStream);
}
}
Document documentPDF = new Document();
PdfWriter writer = PdfWriter.GetInstance(documentPDF, allFrameStream);
}
始终为allFrameStream的
Length=0
。但是每次迭代我都可以看到ms.Length=989548
。我的代码有什么错误?为什么ms.CopyTo(allFrameStream)
不起作用? 最佳答案
填充后将Position
的ms
重置为0:
enc.Save(ms);
ms.Position = 0;
ms.CopyTo(allFrameStream);
从
Stream.CopyTo
关于c# - MemoryStream.CopyTo不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22145836/