我想通过使用下面的代码将MemoryStream转换为图像。如何将流转换为BitmapImage?
Stream stream = new MemoryStream(bytes);
BitmapImage bitmapImage = new BitmapImage();
await bitmapImage.SetSourceAsync(stream.AsRandomAccessStream());
但将在SetSourceAsync
方法一个异常,异常是
System.Exception的是由用户代码 的HResult = -2003292336 消息未处理=该组件无法找到。在 在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务) 在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotificat 离子(任务的任务) :(从HRESULT异常: 0x88982F50) 源= mscorlib程序 堆栈跟踪System.Runtime.CompilerServices.TaskAwaiter.GetResult() 在ImageEditor_UWP.MainPage.d__1.MoveNext()的InnerException:
我怎么能转换成一个流的图像?
使用try/catch块 – Akshay
你能分享你的源代码?我复制了你的代码,并且运行良好https://github.com/haison8x/sample-uwp-bitmapimage –