[英]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. 当我尝试从XML文件中发送的base64编码的字符串创建图像时,出现严重灾难性错误错误。 I have the back-end guy who says it works but he uses WPF and Silverlight is different. 我有一个后端人员说可以,但是他使用WPF,而Silverlight与众不同。
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);
im.SetSource(ms);
行上的错误im.SetSource(ms);
Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)) 灾难性故障(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. 但是,BitmapImage与WPF表亲的主要区别在于它仅支持JPEG和PNG。 Check that one of these formats is being used. 检查是否正在使用这些格式之一。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.