简单问题:怎样把网上的图片显示在PictureBox中 我有一个PictureBox,希望在这个PictureBox里面显示网上的一张图片(网址已经知道)请问该怎样写代码? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果是webform你就直接写网址就好了如果是winform你可以用WebClient或者WebRequest得到这个图片在显示 pictureBox1.Image = Image.FromStream(System.Net.WebRequest.Create(url).GetResponse().GetResponseStream()); private Image GetImage(string url) { System.Net.WebClient client = new System.Net.WebClient(); string ext=""; byte[] buf=null; try { buf = client.DownloadData(url); int begin = url.LastIndexOf('.'); ext = url.Substring( begin ,url.Length - begin); System.IO.FileStream file = new System.IO.FileStream( "c:\\aa" + ext , System.IO.FileMode.OpenOrCreate,System.IO.FileAccess.Write); file.Write(buf,0,buf.Length); file.Close(); return Image.FromFile("c:\\aa" + ext); } catch( Exception e1) { } return null; }//调用 this.pictureBox1.Image = this.GetImage("http://www.baidu.com/img/logo.gif"); this.pictureBox1.Refresh(); private Image GetImage(string url) { System.Net.WebClient client = new System.Net.WebClient(); byte[] buf=null; try { buf = client.DownloadData(url); System.IO.MemoryStream mem = new System.IO.MemoryStream(buf); return Image.FromStream(mem); } catch( Exception e1) { } return null; }//调用 this.pictureBox1.Image = this.GetImage("http://www.baidu.com/img/logo.gif"); this.pictureBox1.Refresh(); 置顶显示的问题 用ClientProfile发布并且需要Access,遇到的问题 何时使用事件?好像感觉没啥必要用到! 从资源文件中修改pictureBox的图片 问个有关模块的问题 动态生成的TextBox,隐藏后在jsp中访问不到 帮个忙,把按钮与快捷键绑定到一起呢,这样语句怎么写呢? 使用ado.net访问远程sqlserver上的链接数据库(链接access),在2003下调试没有问题,但是在2000或者xp上旧有问题?来者有分 吐血求教!DataAdapter的一个简单的update问题,居然出错! 乱码问题 怎样取得DataList中选择的数据 想找一个c#方面的老师在上海
如果是winform你可以用WebClient或者WebRequest得到这个图片在显示
{
System.Net.WebClient client = new System.Net.WebClient();
string ext="";
byte[] buf=null;
try
{
buf = client.DownloadData(url);
int begin = url.LastIndexOf('.');
ext = url.Substring( begin ,url.Length - begin);
System.IO.FileStream file = new System.IO.FileStream( "c:\\aa" + ext , System.IO.FileMode.OpenOrCreate,System.IO.FileAccess.Write);
file.Write(buf,0,buf.Length);
file.Close();
return Image.FromFile("c:\\aa" + ext);
}
catch( Exception e1)
{
}
return null;
}
//调用
this.pictureBox1.Image = this.GetImage("http://www.baidu.com/img/logo.gif");
this.pictureBox1.Refresh();
{
System.Net.WebClient client = new System.Net.WebClient();
byte[] buf=null;
try
{
buf = client.DownloadData(url);
System.IO.MemoryStream mem = new System.IO.MemoryStream(buf);
return Image.FromStream(mem);
}
catch( Exception e1)
{
}
return null;
}
//调用
this.pictureBox1.Image = this.GetImage("http://www.baidu.com/img/logo.gif");
this.pictureBox1.Refresh();