Thadeu Fernandes Thadeu Fernandes - 11 days ago 6
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 = @"http://www.hephaestusproject.com/blog/wp-content/uploads/2014/01/csharp3.png";
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

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.