get image width from URI instead of file

how can i get an image's height and width in the code behind (using vb) when the source of the image is a URI?

i can't use the image.fromfile() because it needs a root directory structure.
Who is Participating?
Jesse HouwingConnect With a Mentor Scrum Trainer | Microsoft MVP | ALM Ranger | ConsultantCommented:
You can use the WebClient to download the image and use the Image.FromStream constructor:

 string url = "";
            WebClient wc = new WebClient();
            Image img =  Image.FromStream(new MemoryStream(wc.DownloadData(url)));

As it's the browser that will be fetching the image, you need to use something like the System.Net.WebClient to download the image from the URI. You can then create am image from a stream containing the bytes, and fetch the size from it. I'd cache the size so that you don't have to do this every time the page is loaded.
Of course, if the image is on the local server, then just use Server.MapPath
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.