Thadeu Fernandes Thadeu Fernandes - 1 year ago 96
C# Question

Get image dimensions directly from an URL C#

I'm getting the image dimensions directly from the internet using this code:

string image = @"";
byte[] imageData = new WebClient().DownloadData(image);
MemoryStream imgStream = new MemoryStream(imageData);
Image img = Image.FromStream(imgStream);

int wSize = img.Width;
int hSize = img.Height;

It works but the performance is terrible because I need to download so many images just to get their dimensions. Is there a faster way to do the same thing?

Answer Source

In a word, no.

In a few more words, you would have to rely on there being a resource containing details of the dimensions of images on a given server. In 99.99% of cases that will simply not exist.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download