MemoryStream.CopyTo不工作 [英] MemoryStream.CopyTo Not working

查看:126
本文介绍了MemoryStream.CopyTo不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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的长度= 0 。但每次迭代我可以看到 ms.Length = 989548 。什么是我的代码错误。为什么 ms.CopyTo(allFrameStream)不工作?

Always allFrameStream's Length=0. But each iteration I could see ms.Length=989548. What is the error in my code. why ms.CopyTo(allFrameStream) is not working?

推荐答案

重置位置 MS 0您填写后:

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



从的 Stream.CopyTo

开始复印在当前流

这篇关于MemoryStream.CopyTo不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆