简体   繁体   中英

How to show image download from a url in mvc3

I downloaded a image by using this method .

 public Image getImageFromURL(String sURL)
    {
        using (WebClient wc = new WebClient())
        {
            var data = wc.DownloadData(sURL);
            var image = Image.FromStream(new MemoryStream(data));
            return image;
        }

    }

In my razor view and it returns me Bitmap object , but when i want to show the downloaded in image then it doesn't work

Thanks in advance

If you get Image in response from your getImageFromURL(String sURL) method. you need to store image at any location in your application, then you can render it on view. you can use this code.

var image = Image.FromStream(new MemoryStream(data));

string path=Path.Combine(Server.MapPath("~/images"), imagename); image.Save(path);

this will save image at your images folder, and then you can render your image from this images folder location on view.

<img src="~/images/imagename" alt="" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM