Monday, November 22, 2010

Get the resolution of a jpeg image using C# and the .NET Environment


Using System.Drawing.Image;

It depends what you are looking for... if you want the DPI of the image then you are looking for the HorizontalResolution which is the DPI of the image.

Image i = Image.FromFile(@"fileName.jpg");

If you want to figure out how large the image is then you need to calculate the measurements of the image which is:

int docHeight = (i.Height / i.VerticalResolution);
int docWidth = (i.Width / i.HorizontalResolution);

This will give you the document height and width in inches which you could then compare to the min size needed.