locked
BitmapDecoder to read a Ico fails

    Question

  • I'm trying to download an .ico and save it to .jpg to show on a Image control, but BitmapDecoder.CreateAsync(BitmapDecoder.IcoDecoderId, stream) throw except and said "The image is unrecognized. (Exception from HRESULT: 0x88982F60)"

    var request = (HttpWebRequest)WebRequest.Create("http://www.cnn.com/favicon.ico");                
    var webResponse = await request.GetResponseAsync();
    var responseStream = webResponse.GetResponseStream();
    
    StorageFile localIconFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("cnn.ico", CreationCollisionOption.ReplaceExisting);
    
    byte[] buffer = new byte[4096];
    int bytesRead = 0;
    using (var stream = await localIconFile.OpenStreamForWriteAsync())
    {
        while ((bytesRead = responseStream.Read(buffer, 0, buffer.Length)) != 0)
        {
            stream.Write(buffer, 0, bytesRead);
        }
    }
    
    var resultStream = await localIconFile.OpenAsync(FileAccessMode.Read);
    
    var decoder = await BitmapDecoder.CreateAsync(BitmapDecoder.IcoDecoderId, resultStream);
    var provider = await decoder.GetPixelDataAsync();
    var pixelData = provider.DetachPixelData();


    Shi Bai

    Tuesday, May 06, 2014 6:47 PM

Answers

  • Hi Shi Bai,

    I tried your code, I can run to the last line without any exception or error message.

    Probably you need to validate your network connection when you trying to start a web request.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Wednesday, May 07, 2014 3:13 AM
    Moderator