Solved

get image width from URI instead of file

Posted on 2010-09-22
2
705 Views
Last Modified: 2012-05-10
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
Comment
Question by:attipa
2 Comments
 
LVL 17

Accepted Solution

by:
Jesse Houwing earned 500 total points
ID: 33741922
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
 
LVL 15

Expert Comment

by:oobayly
ID: 33742071
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Jquey and footrable 2 34
LINQ - C# to VB convertion 12 45
What .NET URL re-routing tool did I use? 2 31
Compile Error 7 39
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now