美文网首页
文件下载/在线预览图片

文件下载/在线预览图片

作者: 飞天猪Pony | 来源:发表于2020-11-09 18:57 被阅读0次
    //在线图片下载
     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");
                }
    }
    

    相关文章

      网友评论

          本文标题:文件下载/在线预览图片

          本文链接:https://www.haomeiwen.com/subject/vllrbktx.html