C# 显示本地文件夹或网络中的图片

C# 显示本地文件夹或网络中的图片,c#,image,download,C#,Image,Download,图像Shello- 我想在picturebox中显示本地文件夹中的图片,但是如果该图片无法加载,我想从网站下载图片并显示它。我不知道该怎么做,但我得到的是: try { pictureBox1.Image = System.Drawing.Image.FromFile("images\\" + filename + "_0001.gif"); XmlIn1.Close();

图像Shello-

我想在picturebox中显示本地文件夹中的图片,但是如果该图片无法加载,我想从网站下载图片并显示它。我不知道该怎么做,但我得到的是:

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();

                }

为什么不使用
ImageLocation
属性

pictureBox1.ImageLocation = "http://skins.gmodules.com/ig/images/logos/approved/beveled_white.png";
上面的代码将显示来自Web的Google徽标。

请尝试以下操作

WebClient wc = new WebClient();
MemoryStream ms = new MemoryStream(wc.DownloadData(<imgURL>));
pictureBox1.Image = Image.FromStream(ms);
WebClient wc=新的WebClient();
MemoryStream ms=新的MemoryStream(wc.DownloadData());
pictureBox1.Image=Image.FromStream(毫秒);