Welcome my friend to the most complicated question you may have ever asked. but I am here to show you the way!
First off, all drawing in GDI+ is done based on pixels... now that means nothing to a printer, because of a little concept called pixel density! better known as dots per inch, or! DPI!!!
now DPI varies from display to display. and according to printer settings! so in theory, if your printer was set up to directly print whatever you sent to it... and you drew a 300 px line, and printed it at a 300 DPI you would then have a 1 inch long line!
but wait!!! that means every picture you printed off the web would look like a postage stamp! YUK!!!
that's because we forgot about resolution... now the resolution of an image is how many Pixels there are in any given unit of measurement.
standard web resolution is 72 pixels per inch. so if your line is 300 px wide, and the printer is set to a DPI of 300 the actual print size on paper would be approximately 4.2 inches!
now to keep things looking consistent printer drivers scale images based on their resolution and DPI, so images of the same pixel size always come out the same size on paper, they just look better with more dots. so ignore the target printer DPI settings in your battle to create print graphics.
you need to focus on the resolution of the images you create!
back to our 300px line example, with a resolution of 72 pxperinch, we got a 4.2 inch line on paper... well if the image resolution were 144 we would get a better quality image, but it would be the same size on screen, but half the size in print! so our 300px image, which look the same size on screen, then prints to 2 inches!
So, if you are only concerned with being able to print an image to an exact size, all you need to be concerned with is the resolution of the image you are printing.
Now here comes the trick, as far as .net 3.5 is concerned. any image type that inherits from "Image" is going to be have a resolution of 96 Pixles/Inch. regardless of the the original resolution of the image. if you create a new bitmap, its 96 Pixles/Inch.
(this could be a system independent piece of information, but all the research I have done concludes to this. to be sure, just use the Image, or Bitmap.HorizontalResolution property in your conversions. it for me and my colleges has always returned 96)
this means if you create a new bitmap image of 300px, and draw a line across all 300px of it, and print it out without scaling it. you will have a measurable print of 3.125 Inches or almost 8 CM.
so you simply divide pixels by resolution to get actual print size.
since .net bitmaps are always 96Px/In (for some unknown reason)
Pixles/resolution = print size.
300px / 96 px/In = 3.125in printsize
or since there are 2.54 CM in an In.
300px / 37.796 px/CM = 7.937CM printsize
i hope this clears up your troubles!
Last edited by Diamonddrake; Sep 16th, 2009 at 8:43 pm.