6

What is difference in between the b.Height and b.Width properties and the b.HorizontalResolution and b.VerticalResolution in C#?

Bitmap b = new Bitmap(@"foo.bmp");

For my sample, Height = 65, Width = 375, HorizontalResolution = VerticalResolution = 150.01239 . MSDN says height and width are in pixels, but the HorizontalResolution and the VerticalResolution are pixel per inch. So, does that mean that is the dpi at which this image was scanned from a scanner for example? Or is this something else?

The context of the question is the following: I would like to scan a signature and show in it on an asp.net page as an image in a form. The form is a standard government form with clearly defined space for the siganture. What considerations should I take into account when I scan the image so that it displays without any fuzziness when I see it in the browser and when I print the web-page.

What I don't understand is if all image formats store (a) the pixel size of the image (height/width) that the browser will display/resize in the image tag and (b) some other dpi equivalent that the printer will use to print? If not what determines the image size on a printed paper?

Raghu Dodda
  • 1,505
  • 1
  • 21
  • 28

2 Answers2

13

The dots-per-inch property is important when you want to make sure that an image is displayed on an output device with the same physical size as when it was created. The best example is an image you create with Microsoft Paint. While you work on it, you use your monitor. Which typically has a resolution of 96 pixels per inch. So a 960 x 960 image will display as (roughly) a 10 x 10 inch image on your monitor.

Now you print it. Printers are high resolution devices, 600 dots per inch is pretty normal. Which means that your 960 x 960 pixel image will be printed as a 960 / 600 = 1.6 x 1.6 inch image on paper. Your nice design turned into a postage stamp.

Clearly that's not desirable, the image needs to be rescaled to look similar on paper as it does on the monitor. The dots-per-inch property of the image lets you do this. The Image.Horizontal/VerticalResolution properties tell you 96, the printer's Graphics.DpiX/Y tell you 600, you know you have to rescale by 600/96 to get the same size image.

Do note that there's a side-effect. Every one pixel you drew in Microsoft Paint is turned into a 6 x 6 blob on paper due to the rescaling. The pixels on the paper are very small though so the image is likely to look the same. As long as the image has smooth transitions, like a photo. What does not work well is text, especially the anti-aliased kind. Which is otherwise why screen-shots look so much poorer compared to a report that was generated for a printer.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • So, if I know that (a) the signature image has to print as 3" x 4" on paper and (b) it has to print **well** @600 dpi, is it then accurate to say that when I scan the image, I have to ensure that (a) it has 1800 x 2400 pixels (the bitmap's height and width properties) and (b) that the dpi (the bitmap's horizontal and vertical resolution) is 600? When the printer prints at @300 dpi, the print driver will scale the image to be 900 x 1200 so that it is still 3" x 4" on paper? – Raghu Dodda Jun 03 '11 at 00:36
  • Scanners don't usually give you any choice. A printer driver doesn't do any scaling, it has to be done by the software that generates the printout. You didn't say what you use. – Hans Passant Jun 03 '11 at 01:00
  • Thanks for the response, Hans. The signature image needs to be displayed on a html web-page as part of a larger form and when the user uses the browser's print from the menu, it must print the image as 3"x 4". Given this information, what must I care about when I scan? Also, if indeed the image needs to be 1800 x 2400 pixels, I need to set the html img size tag to something way smaller (180 x 240 or something) so that it is a reasonable size on the screen. Would what I set as height and width for the image tag impact the size of the image when printed at all or not? – Raghu Dodda Jun 03 '11 at 04:47
0

The Vertical/HorizontalResolution properties tell you how many pixels per inch this image is defined as using. So heres some examples..

An image of 100 px by 100 px @ 50x50 ppi means that when printed the image will consume 2in by 2in. (100 / 50)

Using your numbers: 375 x 65 @ 150.01239 = ~2.5 x .43 inches.

The average computer monitor is set to 72 ppi, but this is not guaranteed.

Sam Axe
  • 33,313
  • 9
  • 55
  • 89