Alex Rivera | Logout

How do I reliably get an image dimensions in .NET without loading the image?

Asked 2009-02-16T07:15:58.183
30

I know how to get the size (x,y) of an image

Image.FromFile("cat.jpg").Size

BUT that requires loading the image from memory.

When I view the images in Windows Explorer it shows me the size.

  • How do I access that size?
  • Is it reliable for all images? Does Windows explorer need to have 'seen' the image first for that size to be available. I don't want to upload my images to a server and have no metadata available if I never opened the folder.
Edit
Report

1 Answer

4

The article Reading Image Headers to Get Width and Height provides several solution possibilities:

  • Multi-threading
  • Reading file headers, reverting to full image load if header is lacking
  • Creating your own index for image attributes
answered 2010-10-15T15:21:52.303

Your Answer