Search code examples
c#windows-phone-8memorystreambitmapimage

Error when setting MemoryStream as the source of a BitMapImage


For Windows Phone 8 development, everything I've read is saying that you have to set a stream as the source of a bitmapimage in order to convert a byte[] array to a bitmapimage. When I implement this though, I receive an error at:

 bitmapImage.SetSource(stream);   

Error:

 An exception of type 'System.Exception' occurred in System.Windows.ni.dll 
 but was not handled in user code

 Additional information: The component cannot be found. (Exception from 
 HRESULT: 0x88982F50) 

Code Snippet:

 byte[] bytes = value as byte[];
 MemoryStream stream = new MemoryStream(bytes, 0, bytes.Length);
 BitmapImage bitmapImage = new BitmapImage();
 bitmapImage.SetSource(stream);

Solution

  • The array you have stored in bytes is not a valid image. You need to go further back to wherever value is getting populated and find out why it is not being populated with the byte array for a image.