您的位置:首页 > 编程语言 > C#

C# 图片流下载;图片流输出

2015-10-10 17:03 441 查看
图片流下载

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


图片流输出

FileStream fs = new FileStream(Server.MapPath(imgLocalPath), FileMode.Open);//将图片文件存在文件流中
long fsLength = fs.Length;//流长度
byte[] b = new byte[(int)fsLength];//定义二进制数组
fs.Read(b, 0, (int)fsLength);//将流中字节写入二进制数组中
fs.Close();//关闭流
Response.ContentType = "image/jpg";//没有这个会出现乱码
Response.BinaryWrite(b);//将图片输出在页面
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: