我想通過使用下面的代碼將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 –