Dark Knight
Dark Knight

Reputation: 3577

how to improve quality of print when I print Win Form in C#

I am trying to print my form using GDI ,but when I print it ,the quality of the print is not that good(donknow whether Image getting aliased?) ,form size is 700x700 ,also there is one parameter which dint understood -raster op code-,here is code am using...

  private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
    {
        Graphics g1 = this.CreateGraphics();
        System.Drawing.Image MyImage = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height, g1);
        Graphics g2 = Graphics.FromImage(MyImage);
        IntPtr dc1 = g1.GetHdc();
        IntPtr dc2 = g2.GetHdc();
        BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);
        g1.ReleaseHdc(dc1);
        g2.ReleaseHdc(dc2);
        Bitmap bmp = new Bitmap(MyImage);

        int x = e.MarginBounds.X;
        int y = e.MarginBounds.Y;
        int width = bmp.Width;
        int height = bmp.Height;
        if ((width / e.MarginBounds.Width) > (height / e.MarginBounds.Height))
        {
            width = e.MarginBounds.Width;
            height = bmp.Height * e.MarginBounds.Width / bmp.Width;
        }
        else
        {
            height = e.MarginBounds.Height;
            width = bmp.Width * e.MarginBounds.Height / bmp.Height;
        }
        System.Drawing.Rectangle destRect = new System.Drawing.Rectangle(x, y, width, height);
        e.Graphics.DrawImage(bmp, destRect, 0, 0, bmp.Width, bmp.Height, System.Drawing.GraphicsUnit.Pixel);
    }

Upvotes: 3

Views: 2068

Answers (2)

OtherControls
OtherControls

Reputation: 29

Maybe you have a problem with the original image. Give me a link to an image. Check the image size.

Try insert line g2.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;

Good luck!

Upvotes: 1

Mario Vernari
Mario Vernari

Reputation: 7304

It is normal that the result will be scaled and aliased. The source has too few pixels compared to the resolution of a modern printer. Consider using WPF, that uses a vector based rendering thus there's no loss/distortion when scaling. Cheers

Upvotes: 0

Related Questions