I would like to find the height/width of an image on disk without opening it, if possible (for performance reasons).
The Windows properties pane for images contains information like width, height, bit depth, etc., which leads me to believe that it is storing metadata on the file somewhere. How can I access this information?
Use System.Drawing.Image class.
Image img = Image.FromFile(fileName);
ImageFormat format = img.RawFormat;
Console.WriteLine("Image Type : "+format.ToString());
Console.WriteLine("Image width : "+img.Width);
Console.WriteLine("Image height : "+img.Height);
Console.WriteLine("Image resolution : "+(img.VerticalResolution*img.HorizontalResolution));
Console.WriteLine("Image Pixel depth : "+Image.GetPixelFormatSize(img.PixelFormat));
Console.WriteLine("Image Creation Date : "+creation.ToString("yyyy-MM-dd"));
Console.WriteLine("Image Creation Time : "+creation.ToString("hh:mm:ss"));
Console.WriteLine("Image Modification Date : "+modify.ToString("yyyy-MM-dd"));
Console.WriteLine("Image Modification Time : "+modify.ToString("hh:mm:ss"));
There are some stackoverflow questions on how to read the EXIF information from images, such as: How to get the EXIF data from a file using C#
The easiest way to accomplish this is, assuming the image is square is to take the file size in bytes and take the square root. This will be your width and height.
256 bytes = 16px x 16px
:-)
Or, you can try reading the image's EXIF information using this codeplex library
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With