源我想设置图片的来源如下:设置图片来自网络
private void buttonGet_Click(object sender, RoutedEventArgs e)
{
string website_url =HttpUtility.UrlEncode(textBoxURL.Text);
WebClient wc = new WebClient();
wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted);
Uri favIconUri = new Uri("http://g.etfv.co/"+ website_url ,UriKind.Absolute);
wc.OpenReadAsync(favIconUri, wc);
}
void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
if (e.Error == null && !e.Cancelled)
{
try
{
BitmapImage image = new BitmapImage();
image.SetSource(e.Result);
image1.Source = image;
}
catch (Exception ex)
{
//Exception handle appropriately for your app
int i = 0;
}
}
else
{
//Either cancelled or error handle appropriately for your app
}
}
}
我得到异常: {"The request is not supported. "}
符合image.SetSource(e.Result);
文本框网址为“http:// google.com“ 所以形成的网址是:”http://g.etfv.co/http%3a%2f%2fwww.google.com“ 我无法弄清楚一件简单的事情。
我尝试使用简单的URL为“http://img.technospot.net/Windows-Phone-7-Theme-Symbian.jpg”(而不是“http://g.etfv.co/foo-bar “然后它的工作原理,但不是我的方式编码。
任何不正确的?
为什么不只是做新的BitmapImage(favIconUri)? – 2012-03-17 13:54:38
试图..不起作用。 我想展示一些进步等 – 2012-03-17 13:58:27
该图像不显示,也没有在这种情况下抛出一个错误 – 2012-03-17 14:00:52