//在线图片下载
WebRequest myrequest = WebRequest.Create("https://***/share/share.jpg");
WebResponse myresponse = myrequest.GetResponse();
Stream imgstream = myresponse.GetResponseStream();
Image img = Image.FromStream(imgstream);
MemoryStream ms = new MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
return File(ms.ToArray(), "image/png", "EDM_大会.png");
//图片在线查看
private readonly IHostingEnvironment _hostingEnvironment;
public rController( IHostingEnvironment hostingEnvironment)
{
_hostingEnvironment = hostingEnvironment;
}
public async Task<ActionResult> p(string tc,string t)
{
string webRootPath = _hostingEnvironment.WebRootPath;
using (var sw = new FileStream(webRootPath + "/img/share.jpg", FileMode.Open))
{
var bytes = new byte[sw.Length];
sw.Read(bytes, 0, bytes.Length);
sw.Close();
return new FileContentResult(bytes, "image/jpeg");
}
}
网友评论