Reputation: 17
I created a fixed 600X600 pixel size bitmap image,
drew something inside and tried to print it, each
time using a different print resolution from the printer
available PrinterSettings.PrinterResolutions
.
PrintDocument pd = new PrintDocument();
PrinterResolution pr = pd.PrinterSettings.PrinterResolutions[printResCB.SelectedIndex];
pd.DefaultPageSettings.PrinterResolution = pr;
pd.PrintPage += PrintPage;
pd.Print();
private void PrintPage(object o, PrintPageEventArgs e)
{
System.Drawing.Image img = pictureBox1.Image;
Point loc = new Point(100, 100);
e.Graphics.DrawImage(img, loc);
}
The printed document in all different print resolutions comes out in the exact same size. I would expect for a constant image size that each printing resolution should result in a different image size.
Eventually I am looking to know the pixels to mms conversion for each of the specific resolution.
What am I doing wrong?
Upvotes: 1
Views: 2980
Reputation: 54433
The PrinterResolutions
has no influence on the size of the printout. It merely tells the printer which of his internal resolutions it should apply to the data it prints. If the printer honors the setting the result will look grainier (lo-res) or paler (eco) but will always have the size you feed into the three relevant parameters:
PageUnit
tell how to read the numbers you send, e.g. pixels, mm, 1/100 inch..PageScale
is a correction factorDrawImage
format that sends not just a Location
but a full Rectangle
i.e. includes a Size
.This will print the image scaled to a square of 15cm. (50mm*3)
e.Graphics.PageUnit = GraphicsUnit.Millimeter;
e.Graphics.PageScale = 3f;
e.Graphics.DrawImage(pictureBox1.Image, new Rectangle(0, 0, 50, 50));
To see the changes in the output size you expected from the resolution you see in the PrinterResolutions
collection you will have to analyse the numbers and calculate the parameters accordingly.
Upvotes: 2