views:

4791

answers:

6

Our clients will be uploading images to be printed on their documents and we have been asked to come up with a way to get the resolution of the image in order to warn them if the image has too low of a resolution and will look pixalated in the end-product

If it comes to it we could also go with the dimensions if anyone knows how to get those but the resolution would be preferred

Thank you

+6  A: 

System.Drawing.Image

Image newImage = Image.FromFile("SampImag.jpg");
newImage.HorizontalResolution
Xian
+2  A: 
Image image = Image.FromFile( [file] );
GraphicsUnit unit = GraphicsUnit.Point;
RectangleF rect = image.GetBounds( ref unit );
float hres = image.HorizontalResolution;
float vres = image.VerticalResolution;
jlew
+3  A: 

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");
i.HorizontalResolution;

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.

Brian ONeil
+1. Brian, you saved me from hours and hours of research, great insight!
Otaku
A: 

Is there a problem with these calculations or is it just me!? I have a .png file that Photoshop says the following about it:

Resolution: 72 dpi
Width: 360px = 5"
Height: 100px = 1.388"

And when I print it at 100% (1:1) scale, it's exactly as Photoshop says

but C# insists on the following info:

Resolution: 96 dpi
Display Size (WxH): 360 x 100 pixels
Print Size (WxH): 3.75" x 1.041667" (according to what I found here...)

Is there something wrong??

Update! I just learned that no matter what Photoshop says and does; The resolution is always 96 dpi! Even when I re-size the image to 600 dpi in photoshop, C# still insists on that 96dpi!

My project is an ASP.NET Web.App-AJAX, BTW

Achilles
A: 

I'm having the same problem. In fact, Windows XP thinks the image is 96dpi as well. But Photoshop says 72dpi and my MacBook says 72dpi, so I'm inclined to believe them. Surely someone else has run into this problem? How can .net have such a huge and ridiculous bug?

colour me brad
+1  A: 

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

Back to the '80s, Mac used 72dpi screen/print resolution to fit the screen/print size, so when you had an image on screen at 1:1, it correspond to the same size on the printer. Windows increased the screen resolution to 96dpi to have better font display.. but as a consequence, the screen image doesn't fit the printed size anymore.

So, for web project, don't bother with DPI if the image isn't for print; 72dpi, 96dpi, even 1200dpi should display the same.

Gabriel Mailhot