您的位置:程序门 -> .net技术 -> c#



picturebox控件,如何载入网上图片?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


picturebox控件,如何载入网上图片?[已结贴,结贴人:bary]
发表于:2007-01-20 21:46:30 楼主
picturebox控件,如何载入网上图片?

picturebox1.image=???请问如何填写
发表于:2007-01-20 21:47:351楼 得分:0
网上图片的地址,比如:http://fchart.sina.com.cn/newchart/min/sz184696.gif
发表于:2007-01-20 22:03:222楼 得分:0
在窗体中放一个webbrowser,然后将webbrowser的url属性设成图片的网址。
发表于:2007-01-20 22:10:383楼 得分:0
用picturebox不行吗?webbrowser控件找不到啊
发表于:2007-01-20 23:24:364楼 得分:0
string   s   =   "http://www.google.com/intl/zh-cn_all/images/logo.gif ";
system.net.httpwebrequest   req   =   (system.net.httpwebrequest)system.net.httpwebrequest.create(s);
system.net.httpwebresponse   res   =   (system.net.httpwebresponse)req.getresponse();
this.picturebox1.image   =   image.fromstream(res.getresponsestream());
发表于:2007-01-20 23:41:205楼 得分:0
picturebox1.image= "http://www.aaa.com/pictures/a.jpg "
发表于:2007-01-21 11:09:326楼 得分:0
关注,楼上的兄弟,写的能行嘛?
发表于:2007-01-21 13:06:567楼 得分:0
duan17()  
你的方法也不行啊,有没有其他的办法
发表于:2007-01-21 13:23:308楼 得分:0
duan17()的方法是可行的
  也许是lz你写错了吧
发表于:2007-01-21 15:15:409楼 得分:0
我也问个问题   在你不知道图片大小的前提下,怎么去动态的设置picturebox控件的大小去跟你在网上加载的图片大小相同?
发表于:2007-01-21 15:15:5110楼 得分:0
pic不能直接调用网络图片的,2楼正解
发表于:2007-01-21 15:17:0211楼 得分:0

int   i=   image.fromstream(res.getresponsestream()).size.height;
this.picturebox1.height   =i;
int   j=   image.fromstream(res.getresponsestream()).size.width;
this.picturebox1.width   =j;

好象不对呀。   谁看看应该怎么写
发表于:2007-01-21 18:44:1612楼 得分:0
duan17()   方法

s=@ "http://www.google.com/intl/zh-cn_all/images/logo.gif ";
system.net.httpwebrequest   req   =   (system.net.httpwebrequest)system.net.httpwebrequest.create(s);
system.net.httpwebresponse   res   =   (system.net.httpwebresponse)req.getresponse();
picturebox1.image   =   image.fromstream(res.getresponsestream());
可行,但是下面却不行,我仅仅换一个地址而已
s=@ "http://fchart.sina.com.cn/newchart/min/sz184696.gif ";
system.net.httpwebrequest   req   =   (system.net.httpwebrequest)system.net.httpwebrequest.create(s);
system.net.httpwebresponse   res   =   (system.net.httpwebresponse)req.getresponse();
picturebox1.image   =   image.fromstream(res.getresponsestream());

发表于:2007-01-21 19:07:0013楼 得分:0
我发现http://fchart.sina.com.cn/newchart/min/sz184696.gif
这个地址有问题啊,是不是sina使用了什么防盗链技术啊?

谁能解释一下,为什么用duan17()的方法链接
http://fchart.sina.com.cn/newchart/min/sz184696.gif
这个地址却不行
发表于:2007-01-21 19:12:0214楼 得分:0
直接使用picturebox.imagelocation   属性就行了
比如picturebox.imagelocation=http://fchart.sina.com.cn/newchart/min/sz184696.gif
发表于:2007-01-21 19:18:0915楼 得分:0
picturebox似乎没有imagelocation   这个属性啊
发表于:2007-01-22 10:20:0016楼 得分:0
duan17()方法为什么换成
s=@ "http://fchart.sina.com.cn/newchart/min/sz184696.gif ";
这个新浪网的地址就不能用了?大家谁试试?
发表于:2007-01-23 08:48:2817楼 得分:0
问题还没有解决,帖子不能沉啊!
发表于:2007-01-23 09:37:1818楼 得分:0
新浪做了盗链处理
发表于:2007-01-23 09:45:5819楼 得分:0
下面的方法,经测试可用:
using   system.net;
using   system.io;

system.net.webclient   webclient   =   new   webclient();
system.io.stream   stream=webclient.openread(@ "http://123.com/4567.jpg ");
//网址自己改吧
this.picturebox1.image   =   image.fromstream(stream);
stream.dispose();
发表于:2007-01-23 10:27:3220楼 得分:0
如何破解防盗链接技术?
发表于:2007-01-23 10:47:3621楼 得分:20
...
你可以把http://fchart.sina.com.cn/newchart/min/sz184696.gif文件下载到本地
ie可以打开显示
但画图等且不能打开
不是防盗链接,而是图片格式微妙的差别   -_-#
发表于:2007-01-23 16:57:3222楼 得分:0
zswang(伴水清清)(专家门诊清洁工)  
能否具体说说,我用duan17()   方法总是抛出异常,说指向的引用为空
发表于:2007-03-24 10:26:2123楼 得分:0
用webrequest方法下载流。       //下载你指定的图片的url
bitmap构造方法接受该流。     //用这个流变成的图片   装入到你的picturebox控件
using   system.io;
using   system.net;

//.....

httpwebrequest   vhttpwebrequest   =   (httpwebrequest)webrequest.create(
        @ "http://album.sina.com.cn/pic_3/589d32f502000001 ");
httpwebresponse   vhttpwebresponse   =   (httpwebresponse)vhttpwebrequest.getresponse();
binaryreader   vbinaryreader   =   new   binaryreader(vhttpwebresponse.getresponsestream());
memorystream   vmemorystream   =   new   memorystream();
byte[]   vbuffer   =   new   byte[0x1000];
int   vreadlength   =   vbinaryreader.read(vbuffer,   0,   vbuffer.length);
while   (vreadlength   >   0)
{
        vmemorystream.write(vbuffer,   0,   vreadlength);
        vreadlength   =   vbinaryreader.read(vbuffer,   0,   vbuffer.length);
}
vhttpwebresponse.close();
vmemorystream.position   =   0;
picturebox1.image   =   bitmap.fromstream(vmemorystream);
vmemorystream.close();
发表于:2007-03-24 11:10:0224楼 得分:0
c#么?
我教你个最好的方法:
你添加个pb控件后手工添加个图片
完了你去看下vs自动生成的代码是什么样的
估计你一下就明白了
要是你不明白请你退出it业
发表于:2007-03-24 13:22:4025楼 得分:0
难得我不会,不过设置picturebox   sizemode成autosize可以动态调整大小(当前图片的原始大小)


快速检索

最新资讯
热门点击