• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 714
  • Last Modified:

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.
0
attipa
Asked:
attipa
1 Solution
 
Jesse HouwingScrum Trainer | Microsoft MVP | ALM Ranger | ConsultantCommented:
You can use the WebClient to download the image and use the Image.FromStream constructor:

 string url = "http://www.google.com/logo.png";
            WebClient wc = new WebClient();
            Image img =  Image.FromStream(new MemoryStream(wc.DownloadData(url)));

0
 
oobaylyCommented:
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
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now