Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The image header is unrecognized. (Exception from HRESULT: 0x88982F61) in Windows Phone 8 application

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?

like image 224
user1934329 Avatar asked Jun 25 '13 06:06

user1934329


2 Answers

Make sure that imageBytes.Position = 0 before beginning your operations.

like image 105
LawMan Avatar answered Sep 22 '22 04:09

LawMan


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

like image 43
Oren Avatar answered Sep 21 '22 04:09

Oren