0

I am trying to validate certain images to not allow images lower than 300 pixels per inch, is there a way to find it on ASP.NET using C#?

2 Answers2

1

You've got to read EXIF data from the image.

Here you have an example of how you can do it, using ExifLib

ExifLib - A Fast Exif Data Extractor for .NET 2.0+

Be warned that not all jpeg images have the resolution information. And, that even if they have it, you can print them using a completely different resolution. I.e. a pic 200px wide can be printed using 1 inch width is 200dpi. This same image printed using 2 inches is 100dpi, and using 1/2 inch is 400dpi.

EDIT: It's even possible to get this info with native .NET framework Image.PropertyItems Property

JotaBe
  • 38,030
  • 8
  • 98
  • 117
1

The Image object of the .NET Framework will give you the PPI of a Bitmap (including a JPG).

Image image = new Bitmap(@"C:\myimage.jgp");
float ppi = image.HorizontalResolution; // the image's pixels per inch
float widthInInches = image.PhysicalDimension.Width / ppi;

Seems to work for me. I was able to discern that a specific image I am using in a PDF is 90 ppi.

Jeff Johnson
  • 1,095
  • 10
  • 15