12

The above exception occurs at line await bitmapImage.SetSourceAsync(fileStream); whenever I tried to retrieve image from local file.

This is the method I'm using for storing and retrieving the image file.

    public async Task<BitmapImage> RetrieveImageFromFile(String fileName)
    {
        try
        {
            StorageFile localFile = await _storageFolder.GetFileAsync(fileName + "Img");
            BitmapImage bitmapImage = new BitmapImage();
            using (IRandomAccessStream fileStream = await localFile.OpenAsync(FileAccessMode.Read))
            {
                await bitmapImage.SetSourceAsync(fileStream);
            }
            return bitmapImage;
        }
        catch(Exception e)
        {
            return null;
        }
    }

    public async void WriteImageToFile(string fileName, IRandomAccessStreamWithContentType stream )
    {
        StorageFile file = await _storageFolder.CreateFileAsync(fileName + "Img", CreationCollisionOption.ReplaceExisting);
        Stream streamToSave = stream.AsStreamForWrite();
        using (Stream fileStram = await file.OpenStreamForWriteAsync())
        {
            streamToSave.CopyTo(fileStram);
        }
    }

The input stream for the WriteImageToFile method is retrieved from contact.Thumbnail.OpenReadAsync() method

Any help ?

MohanRajNK
  • 895
  • 2
  • 13
  • 26
  • I'm presenting the same issue... Did you find a solution? – Pedrom Jun 29 '15 at 23:46
  • 2
    Hopefully you've worked around this by now but the 0x88982f50 error is generally related to a failure to read/decode an image file correctly. Verify your file is formatted properly. (Google 88982f50 to see dozens of potentially related fixes, all relating to image file I/O.) This turned out to be my problem as well... Bad file. – sraboy Sep 07 '15 at 10:04
  • @sraboy thanks, you saved a day to me :) bad files with 0 bytes size or formatting errors. we should always check if the stream was succesfully created – user3290180 Sep 27 '15 at 15:59
  • have this problem on Windows UWP as well when using the ImageLib. how to you check if the stream was created succesfully? i guess just check if it is not null, and catch the potential exceptions. – terry Jun 27 '16 at 04:23
  • @sraboy You should turn your comment into an answer. I see this error frequently, and I am fairly sure it is caused by erroneous image data from the stream. – Hong Mar 28 '17 at 15:24
  • @Hong, thanks for pointing that out. I've gone ahead and answered the question. – sraboy Mar 28 '17 at 18:28
  • 1
    @sraboy Glad to be the first to up-vote your answer. – Hong Mar 28 '17 at 20:23

2 Answers2

6

Just turning my comment into an answer since it's been helping people:

The 0x88982f50 error is generally related to a failure to read/decode an image file correctly. Verify your file is formatted properly. Google 88982f50 to see dozens of potentially related fixes, all relating to image file I/O. I never did find a definitive source for the error but this turned out to be my problem as well... Bad file.

sraboy
  • 903
  • 2
  • 13
  • 26
4

Late answer but might save someone else from spending hours hunting this down...

Error code 0x88982f50 is WINCODEC_ERR_COMPONENTNOTFOUND, and it's the Windows Imaging Component's way of saying it can't decode an image file.

Most likely the file is corrupted, or the version of WIC installed in Windows doesn't include a codec needed to decode it.

Microsoft provides zero information about it.