Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obtain image width and height without loading image in .NET? [duplicate]

Tags:

c#

asp.net

image

Like the Title, is this possible?

I only need the width and height, so loading the image into ram would be unnecessary.

like image 431
Andreas Avatar asked Sep 18 '25 23:09

Andreas


2 Answers

Check this SO question: Getting image dimensions without reading the entire file

This shows you how to extract this information from the image header without reading the entire file. Usually, the image files contain metadata at the start containing width and height in addition to other data, so that will be the quickest way of retrieving this information.

like image 57
Øyvind Bråthen Avatar answered Sep 20 '25 13:09

Øyvind Bråthen


There is example code here that shows how you can read the header of images to get the width and height without loading and decoding the entire file. Obviously the approach is different for different image types though, so you may need to write your own if you are using something a little more exotic.

like image 40
Martin Harris Avatar answered Sep 20 '25 15:09

Martin Harris