[英]Get image from Webpage and show (Windows Phone)
I'm having abit of trouble getting an image from a website and showing it on Windows Phone. 我在从网站获取图像并将其显示在Windows Phone上时遇到了一些麻烦。 The image link changes every day (http://apod.nasa.gov/apod/astropix.html) but the website link is the same.
图片链接每天都会更改(http://apod.nasa.gov/apod/astropix.html),但网站链接是相同的。
I've seen that many people use HTMLAgility pack, but I don't think I can use it for Windows Phone. 我已经看到许多人使用HTMLAgility包,但是我认为我不能将其用于Windows Phone。
How would I download an image from a webpage and show it in a imageview/picturebox? 如何从网页上下载图像并将其显示在imageview / picturebox中?
I'm assuming it would go something like Parse Website > Get src string > load string > load image > show image. 我假设它会像解析网站>获取src字符串>加载字符串>加载图像>显示图像。 But would really like some help regarding how to do it.
但确实希望获得有关该方法的帮助。
Thanks! 谢谢!
Hi Here's a code block to help. 嗨,这是一个代码块可以提供帮助。 I have not followed the best practices of writing it down still :
我还没有遵循将其写下来的最佳实践:
void ImageDownloader()
{
WebClient client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
client.DownloadStringAsync(new Uri("http://apod.nasa.gov/apod/astropix.html"));
}
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
string str = e.Result.Remove(0,(e.Result.IndexOf("SRC=")+5));
str = "http://apod.nasa.gov/apod/"+str.Substring(0, (str.IndexOf(".jpg")+4));
ImageBrush imb = new ImageBrush();
imb.ImageSource = new BitmapImage(new Uri(str));
LayoutRoot.Background = imb;
}
Home th e string "http://apod.nasa.gov/apod/" remains constant. 字符串“ http://apod.nasa.gov/apod/”的首页保持不变。
Here LayoutRoot is the main grid. 这里LayoutRoot是主网格。 U can use an imageview or a picture box as per ur convinience.
您可以根据自己的喜好使用imageview或图片框。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.