我有一个连接到数据库的Web服务,我需要通过Web服务从该BD中提取一个BLOB类型,然后创建一个Image。 Web服务从团块发送的字节数组,我试图用一个转换器结合到图像中的XML(像一些建议,我发现)像这样Windows Phone 8.0 Blob to Image
using (Stream ms = new MemoryStream(fileBytes, 0, fileBytes.Length))
{
ms.Write(fileBytes, 0, fileBytes.Length);
ms.Seek(0, SeekOrigin.Begin);
BitmapImage bitmapImage = new BitmapImage();
////////////////Exception here
bitmapImage.SetSource(ms);
return bitmapImage;
}
但后来我得到这个错误(异常来自HRESULT: 0x88982F50
)。然后我发现,也许可能是字节数组的格式问题,也许可能在base64
,所以我改变了Web服务,现在它给我一个64基的字符串,然后改变为字节数组,但仍然有相同的错误。
我发现this post但仍然没有运气。然后我找到了很多解决方案,像InMemoryRandomAccessStream
或Image.FromStream
但这些解决方案是WP 8.1
而且我用:
image.SaveJpeg(stream, image.PixelWidth, image.PixelHeight, 0, 90);
///////AND////////
image = PictureDecoder.DecodeJpeg(ms);
但仍没有运气
我敢肯定,我我错过了一些东西,因为每个解决方案都指出了这些解决方案,但我真的无法弄清楚。
我不能使用所有这些方法的BitmapImage可能不支持WP。 'image.BeginInit(); image.CreateOptions = BitmapCreateOptions.PreservePixelFormat; image.CacheOption = BitmapCacheOption.OnLoad; image.UriSource = null; image.StreamSource = mem; image.EndInit();' – killemmanuel
你会得到什么错误?您可能需要添加'使用System.Windows.Media.Imaging;'到您引用'BitmapImage'的文件的顶部。 –
我已经添加了'使用System.Windows.Media.Imaging;'来使用BitmapImage类。我得到的错误是'System.Windows.Media.Imaging.BitmapImage不包含BeginInit的定义而不是扩展方法BeginInit接受类型为System.Windows.Media.Imaging.BitmapImage的firts参数' – killemmanuel