imagesHello -
我想在图片框中显示本地文件夹中的图片,但是如果该图片无法加载,我想从网站下载图像并显示它。我不知道该怎么做,但我拥有的是:
try
{
pictureBox1.Image = System.Drawing.Image.FromFile("images\\" + filename + "_0001.gif");
XmlIn1.Close();
}
catch
{
string downloadPath = "http://www.website.com/images/" + filename + "_0001.gif";
pictureBox1.Image = System.Drawing.Image.FromFile(downloadPath);
XmlIn1.Close();
}
答案 0 :(得分:2)
为什么不使用ImageLocation
属性?
pictureBox1.ImageLocation = "http://skins.gmodules.com/ig/images/logos/approved/beveled_white.png";
以上代码将显示来自网络的Google徽标。
答案 1 :(得分:0)
尝试类似
的内容WebClient wc = new WebClient();
MemoryStream ms = new MemoryStream(wc.DownloadData(<imgURL>));
pictureBox1.Image = Image.FromStream(ms);