Graphics.DrawImage在打印时模糊

时间:2014-07-01 22:04:07

标签: c# printing controls drawimage blurry

我试图在面板上打印内容,但结果非常模糊/抖动。使用DrawToBitmap生成的位图在将其保存到磁盘时非常清晰,但是当我在打印之前使用Graphics.DrawImage或Graphics.DrawImageUnscaled时,它变得非常模糊。我试图打印到PDF和打印机,但结果相同。

    private void button2_Click(object sender, EventArgs e)
    {
        PrintDocument pd = new PrintDocument();
        pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
        pd.Print();
    }

    void pd_PrintPage(object sender, PrintPageEventArgs e)
    {
        e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
        e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

        Bitmap b = new Bitmap(panel1.Width, panel1.Height);
        panel1.DrawToBitmap(b, panel1.ClientRectangle);
        e.Graphics.DrawImageUnscaled(b, new Point(0, 0));
    }

BMP(100%):http://i.gyazo.com/e5785a0bc3efd0de174f71b947aff428.png

PDF打印(100%):http://i.gyazo.com/fd0cc9baf8a485afd2fabb48d5b10bf2.png


编辑:

解:

感谢LarsTech。一些额外的工作,但它肯定解决了我的问题:

    void pd_PrintPage(object sender, PrintPageEventArgs e)
    {
        Pen blackPen = new Pen(Color.Black);
        Brush blackBrush = new SolidBrush(Color.Black);

        // Draw lines and borders -----------------------
        e.Graphics.DrawRectangle(blackPen, ClientRectangle);
        e.Graphics.DrawRectangle(blackPen, panel1.Bounds);
        e.Graphics.DrawRectangle(blackPen, panel2.Bounds);
        e.Graphics.DrawRectangle(blackPen, panel3.Bounds);
        e.Graphics.DrawRectangle(blackPen, panel4.Bounds);
        // .....

        // Draw all text ----------------------------------
        e.Graphics.DrawString(label1.Text, label1.Font, blackBrush, label1.Bounds.Location);
        e.Graphics.DrawString(label2.Text, label2.Font, blackBrush, label2.Bounds.Location);
        e.Graphics.DrawString(label3.Text, label3.Font, blackBrush, label3.Bounds.Location);
        e.Graphics.DrawString(label4.Text, label4.Font, blackBrush, label4.Bounds.Location);
        // .....
    }

0 个答案:

没有答案