开发者

BitmapEncoder/ decoder, memory stream and NotSupportedException c# .net

开发者 https://www.devze.com 2023-03-18 03:18 出处:网络
I have the following code: MemoryStream imageStream; public ImageVideoFrame(BitmapSource frame) { imageStream = new MemoryStream();

I have the following code:

MemoryStream imageStream;

public ImageVideoFrame(BitmapSource frame)
            {  
                imageStream = new MemoryStream();
                BitmapEncoder encoder = new PngBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(frame));
                encoder.Save(imageStream);
                imageStream.Seek(0, SeekOrigin.Begin);
            }

public BitmapSource Frame
           {
                BitmapDecoder decoder = new PngBitmapDecoder(image,
     开发者_StackOverflow                   BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                BitmapSource bitmapSource = decoder.Frames.First();
                return bitmapSource;
           }

used to compress images in memory to reduce memory usage. The problem with the above code is that I get a NotSupportedExcpetion Constructing the PngBitmapDecoder. When debugging the position of the imageStream is shown to be

0

精彩评论

暂无评论...
验证码 换一张
取 消