打印机分辨率通常比屏幕分辨率高5-6倍。打印机的分辨率可以是6600 x 5100左右,而不是全高清屏幕的分辨率:1920 x 1080.
1920 x 1080图像在屏幕上看起来很棒,但为了避免像素化,理想情况下应该为打印机渲染分辨率更高的图像,例如6600 x 5100图像。
我正在尝试将高清晰度图像(6600 x 5100)打印到我的高清打印机(600 dpi),但我发现e.PageBounds指定的可用打印区域仅为850 x 1100;请参阅以下代码:
Bitmap bitmapToPrint;
public void printImage()
{
bitmapToPrint = new Bitmap(1700,2200);
Font font = new Font(FontFamily.GenericSansSerif, 60, FontStyle.Regular);
string alphabet = "abcdefghijklmnopqrstuvwxyz";
Graphics graphics = Graphics.FromImage(bitmapToPrint);
graphics.DrawString(alphabet, font, System.Drawing.Brushes.Black, 0, 0);
graphics.DrawString(alphabet, font, System.Drawing.Brushes.Black, 0, 1000);
PrintDocument pd = new PrintDocument();
pd.PrinterSettings.PrinterName = "Microsoft XPS Document Writer";
pd.PrinterSettings.PrintToFile = true;
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.Print();
}
void pd_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawImage(bitmapToPrint, new PointF(0, 0));
//Have a look at e.PageBounds, the dimensions are only 850x1100
}
正如RogerN指出的那样,要解决这个问题,必须简单地将DrawImage调用替换为:
e.Graphics.DrawImage(bitmapToPrint, new RectangleF(0.0f, 0.0f, 850.0f, 1100.0f));