Get jpeg image resolution using C # and .NET?

Our customers will upload images that will be printed on their documents, and we were asked to come up with a way to get the resolution of the image in order to warn them if the image is too low resolution and will look pixalated in the final product

If it comes to this, we can also go with the sizes, if anyone knows how to get them, but permission would be preferable.

thanks

+6
resolution jpeg
source share
4 answers

System.Drawing.Image

Image newImage = Image.FromFile("SampImag.jpg"); newImage.HorizontalResolution 
+13
source share

It depends on what you are looking for ... if you want DPI images, then you are looking for HorizontalResolution, which is a DPI image.

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

If you want to find out how large the image is, you need to calculate the dimensions of the image, which:

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

This will give you the height and width of the document in inches, which can then be compared with the minimum size.

+8
source share

DPI only makes sense when printing. 72dpi is the Mac standard, and 96dpi is the Windows standard. Screen resolution takes into account only pixels, so 72dpi 800x600 jpeg is the same screen resolution as 96dpi 800x600 pixels.

Back to the 80s, the Mac used 72gpi screen resolution / print resolution according to the screen / print size, so when you had the image on the screen at 1: 1, it corresponds to the same size on the printer. Windows has increased the screen resolution to 96 dpi to improve the display of fonts. But, as a result, the image on the screen is no longer suitable for the printed size.

So, for a web project, don't worry about DPI if the image is not for printing; 72dpi, 96dpi, even 1200 dpi should be displayed the same way.

+3
source share
 Image image = Image.FromFile( [file] ); GraphicsUnit unit = GraphicsUnit.Point; RectangleF rect = image.GetBounds( ref unit ); float hres = image.HorizontalResolution; float vres = image.VerticalResolution; 
+2
source share

All Articles