| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 535 人关注过本帖
标题:显示网络图片
只看楼主 加入收藏
liuerquan
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2011-4-13
结帖率:0
收藏
 问题点数:0 回复次数:3 
显示网络图片
想在打开程序的时候,在图片框中显示网站服务器中的图片(www.****.com/*.jpg)

哪位大哥给写个代码
搜索更多相关主题的帖子: 网站服务器 图片 网络 大哥 
2012-03-21 21:37
a345271593
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-3-24
收藏
得分:0 
图片框名称.ImageLocation = @"图片地址";
2012-03-22 09:31
liuerquan
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2011-4-13
收藏
得分:0 
pictureBox1.ImageLocation = @"http://*****.jpg";

显示不出来呀
2012-03-22 14:25
xydddaxia
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:33
帖 子:466
专家分:2307
注 册:2009-3-20
收藏
得分:0 
程序代码:
string imgUrl = "http://***/456.jpg";//目标图片
            WebRequest webReq = WebRequest.Create(imgUrl);
            WebResponse webRes = webReq.GetResponse();
            long fileLength = webRes.ContentLength;
            try
            {
                Stream srm = webRes.GetResponseStream();
                StreamReader srmReader = new StreamReader(srm);
                byte[] bufferbyte = new byte[fileLength];
                int allByte = (int)bufferbyte.Length;
                int startByte = 0;
                while (fileLength > 0)
                {
                    Application.DoEvents();
                    int downByte = srm.Read(bufferbyte, startByte, allByte);
                    if (downByte == 0) { break; };
                    startByte += downByte;
                    allByte -= downByte;
                }
                string tempPath = Application.StartupPath + "//download.jpg";//临时文件名
                //保存文件
                FileStream fs = new FileStream(tempPath, FileMode.OpenOrCreate, FileAccess.Write);
                fs.Write(bufferbyte, 0, bufferbyte.Length);
                srm.Close();
                srmReader.Close();
                fs.Close();
                //显示下载图片
                this.pictureBox1.Image = Image.FromFile(tempPath);
            }
            catch (WebException ex)
            {
                MessageBox.Show("下载失败!" + ex.Message.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

站在春哥的肩膀上
2012-03-22 15:47
快速回复:显示网络图片
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015605 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved