wpf 解决 编码解码器无法使用提供的流类型 The codec cannot use the type of stream provided

时间:2022-04-25
本文章向大家介绍wpf 解决 编码解码器无法使用提供的流类型 The codec cannot use the type of stream provided,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

之前做的ListBox里列大图https://cloud.tencent.com/developer/article/1032668

图片转换的时候这段代码

有的时候会有问题 编码解码器无法使用提供的流类型 或者 The codec cannot use the type of stream provided

改成

 BitmapImage bitImage = new BitmapImage();
                bitImage.BeginInit();
                bitImage.StreamSource = imageStreamSource;
                bitImage.EndInit();
                //JpegBitmapDecoder jpeDecoder=new JpegBitmapDecoder(imageStreamSource,BitmapCreateOptions.PreservePixelFormat,BitmapCacheOption.OnLoad);
                //ImageSource imageSource=jpeDecoder.Frames[0];
                ImageSource imageSource = bitImage;
                return imageSource;