开发者

displaying picture from local folder or from net

imagesHello -

I want to display a picture from a local folder in a picturebox, howev开发者_JS百科er if that picture fails to load, I woud like to download the image from a website and display it. I have no idea how to do this, but what I have is this:

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

                }


Why not use the ImageLocation property?

pictureBox1.ImageLocation = "http://skins.gmodules.com/ig/images/logos/approved/beveled_white.png";

Above code will display Google Logo from Web.


try something like

WebClient wc = new WebClient();
MemoryStream ms = new MemoryStream(wc.DownloadData(<imgURL>));
pictureBox1.Image = Image.FromStream(ms);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜