0

I'm trying to print the content on a panel, but the result is very blurry / dithered. The bitmap that is generated using DrawToBitmap is perfectly sharp when saving it to the disk, but when I use Graphics.DrawImage or Graphics.DrawImageUnscaled before printing, it gets very blurry. I have tried to both print to PDF and on a printer, but same result.

    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 print (100%): http://i.gyazo.com/fd0cc9baf8a485afd2fabb48d5b10bf2.png


Edit:

SOLUTION:

Thanks LarsTech. Some extra work but it definetly solved my problem:

    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);
        // .....
    }
  • 2
    Your printer has better resolution than your monitor. That bitmap won't work. You will have to recreate the print items directly on the e.Graphics of the PrintPageEventArgs. – LarsTech Jul 01 '14 at 22:08
  • Thanks for the reply! So you mean I have to draw everything manually using e.Grapics' DrawLine(..), DrawString(..) etc? – Even A. Rognlien Jul 02 '14 at 15:56
  • Yes, since you want the sharpness of the printer's resolution. – LarsTech Jul 02 '14 at 16:00

0 Answers0