图片流下载
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);//将图片输出在页面