1

打印机分辨率通常是屏幕分辨率的 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));

4

0 回答 0