Obtain image width and height without loading image in .NET?

15,566

Solution 1

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.

Solution 2

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.

Solution 3

Depending on the image format you can extract the metadata with a library (e.g. EXIF for jpeg)

Maybe this SO question might help: What is the best EXIF library for .Net?

Share:
15,566
Andreas
Author by

Andreas

Updated on July 27, 2022

Comments

  • Andreas
    Andreas almost 2 years

    Like the Title, is this possible?

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