【发布时间】:2012-04-06 01:45:01
【问题描述】:
我有一项服务可以将存储在网站上的图像转换为字节数组
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("URLTOIMAGE");
myRequest.Method = "GET";
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
Bitmap bmp = new Bitmap(myResponse.GetResponseStream());
myResponse.Close();
ms = new MemoryStream();
bmp.Save(ms, ImageFormat.Bmp);
此代码返回我存储在数据库 (SQL Azure) 中的字节数组。在我的 Windows Phone 应用程序中,我尝试转换此字节数组以将其显示在我的页面上。
public class BytesToImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
BitmapImage empImage = new BitmapImage();
empImage.SetSource(new MemoryStream((Byte[])value));
return empImage;
}
public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
字节数组被应用程序很好地接收,但是当我尝试执行 SetSource 时抛出异常。
empImage.SetSource(new MemoryStream((Byte[])value));
=> "Exception was unhandled", The request is not supported
你能帮帮我吗?谢谢
【问题讨论】:
-
你要加载什么类型的图片?
-
这是 JPEG => byte[] 和 byte[] 到 BitmapImage(用于 Imagesource)
标签: c# image windows-phone-7