博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

图片流下载

string filePath = HttpContext.Current.Server.MapPath("/img/wxPic/");
 if (!Directory.Exists(filePath))
{
 Directory.CreateDirectory(filePath);
}
string fileName = string.Empty;
string time = System.Guid.NewGuid().ToString();
fileName = time + ".jpg";
WebClient wc = new WebClient();
wc.DownloadFile(picUrl, filePath + fileName);

 

 

图片流输出

1 FileStream fs = new FileStream(Server.MapPath(imgLocalPath), FileMode.Open);//将图片文件存在文件流中
2 long fsLength = fs.Length;//流长度
3 byte[] b = new byte[(int)fsLength];//定义二进制数组
4 fs.Read(b, 0, (int)fsLength);//将流中字节写入二进制数组中
5 fs.Close();//关闭流
6 Response.ContentType = "image/jpg";//没有这个会出现乱码
7 Response.BinaryWrite(b);//将图片输出在页面

 

posted on 2015-10-10 17:03    阅读(2156)  评论(0编辑  收藏  举报