gpt4 book ai didi

c# - MemoryStream.CopyTo 不工作

转载 作者:可可西里 更新时间:2023-11-01 07:49:39 30 4
gpt4 key购买 nike

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);
}

总是所有 FrameStream 的 Length=0。但是每次迭代我都可以看到 ms.Length=989548。我的代码中有什么错误。为什么 ms.CopyTo(allFrameStream) 不工作?

最佳答案

填充后将 msPosition 重置为 0:

enc.Save(ms);
ms.Position = 0;
ms.CopyTo(allFrameStream);

来自 Stream.CopyTo

Copying begins at the current position in the current stream

关于c# - MemoryStream.CopyTo 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22145836/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com