Here is my code...
public async Task SetLargeImageAsync(byte[] imageBytes,
bool storeBytesInObject = false)
{
var tcs = new TaskCompletionSource<string>();
SmartDispatcher.BeginInvoke(() =>
{
using (MemoryStream ms = new MemoryStream(imageBytes))
{
if (storeBytesInObject)
this.LargeImageBytes = imageBytes;
BitmapImage image = new BitmapImage();
image.SetSource(ms);
this.LargeImage = image;
tcs.SetResult(string.Empty);
}
});
await tcs.Task;
}
I am sending bytes into stream. This works fine; it is showing an image.
But I am getting the following exception sometimes:
The image header is unrecognized. (Exception from HRESULT: 0x88982F61) at MS.Internal.XcpImports.CheckHResult(UInt32 hr) at MS.Internal.XcpImports.BitmapSource_SetSource(BitmapSource bitmapSource, CValue& byteStream) at System.Windows.Media.Imaging.BitmapSource.SetSourceInternal(Stream streamSource) at System.Windows.Media.Imaging.BitmapImage.SetSourceInternal(Stream streamSource) at System.Windows.Media.Imaging.BitmapSource.SetSource(Stream streamSource)
What is the problem? Is there any problem with different types of images?
I found somewhere that we should use following code for seeking beginning position:
ms.Seek(0, SeekOrigin.Begin)
Is it true? What is the solution for that?
Make sure that imageBytes.Position = 0 before beginning your operations.
You're passing in an invalid image - either it's corrupted or stored in a format that WP can't decode natively. The full list of supported formats can be found at: http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff462087(v=vs.105).aspx#BKMK_ImageSupport
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With