简体   繁体   中英

Creating image from base64 encoded string (Silverlight 4.0)

I get a Catastrophic Failure error when I try to create an image from a base64 encoded string sent in an XML file. I have the back-end guy who says it works but he uses WPF and Silverlight is different.

The code:

    void TagCloudImageCompleted(object sender, WebApiTagCloud.TagCloudImageCompletedEventArgs e)
    {
        String cloudImageResult = e.Result;
        //MessageBox.Show(cloudImageResult);

        XDocument cloudImageXML = XDocument.Parse(cloudImageResult);
        String bmpString = cloudImageXML.Element("TagCloudImage").Element("BitMapImage").Value;

        byte[] imageBytes = System.Convert.FromBase64String(bmpString);
        MemoryStream ms = new MemoryStream(imageBytes);
        BitmapImage im = new BitmapImage();
        im.SetSource(ms);
        LocationImage.Source = im;
        ms.Close();
    }

Since his version is working I have tried to verify that the data that I am getting is correct. But I haven't been able to verify with him yet that we are getting similar data.

The error on the line im.SetSource(ms);

Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))

The code looks fine. However a key difference BitmapImage has with its WPF cousin is that it only supports JPEG and PNG. Check that one of these formats is being used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM