Jon
Jon

Reputation: 40032

Printing Windows Form

I have inherited some code to print the contents of a form however the image produced on paper seems to have some sort of shadow/blurriness as if its tried to do anti-alasing but not done so very well and the letters are pixelated on the edges.

Does anyone know a way of improving the final quality?

System.Drawing.Printing.PrintDocument Doc = new System.Drawing.Printing.PrintDocument();
            Doc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.Doc_PrintPage123);
            Doc.DefaultPageSettings.Landscape = true;
            Doc.DefaultPageSettings.PrinterSettings.DefaultPageSettings.Landscape = true;
            Doc.DefaultPageSettings.PrinterSettings.Copies = 2;
            Doc.PrinterSettings.Copies = 2;
            Doc.Print();

 private void Doc_PrintPage123(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
             Bitmap bitmap = new Bitmap(AForm.Width, AForm.Height);
            AForm.DrawToBitmap(bitmap, new Rectangle(0, 0, bitmap.Width, bitmap.Height));
            e.Graphics.DrawImage(bitmap, 0, 0);
        }

Upvotes: 0

Views: 4008

Answers (4)

ahmedcool166
ahmedcool166

Reputation: 21

You can increase the Dbi resolution. Default is 96

var resultImage = new Bitmap(barcodeImage.Width + 160, barcodeImage.Height + 120);
resultImage.SetResolution(200, 200);

Upvotes: 0

Hans Passant
Hans Passant

Reputation: 941208

That's normal. A printer has a resolution that's easily 6 times better than a monitor. With the default mapping (1 pixel = 0.01 inch), you'll get a bitmap on the printer that's about the same size as it is on the screen. With 1 pixel on the screen becoming a blob of 6 x 6 pixels on the printer. Yes, doesn't look great.

You'll get a sharp image if you draw it 6 times smaller. A bit bigger than a postage stamp. Don't print forms. Take advantage of the printer resolution by drawing on e.Graphics. Lots of work of course, report generators like Crystal Reports are popular.

Upvotes: 3

Rune Grimstad
Rune Grimstad

Reputation: 36300

The form is rendered as a bitmap at the resolution it is displayed. The blurrying and pixelation is due to the image having low resolution and you resizing it when printing it.

There is no good way to improve the quality. You could try to resize the image and apply some sort of smoothing mode like Mamta Dalal suggests, but that will only help on the pixelation.

If you really need higher quality you must use another mechanism to print your data. Using some sort of report designer is probably the easiest way to go.

Upvotes: 1

Mamta D
Mamta D

Reputation: 6450

Try this: e.Graphics.SmoothingMode = SmoothingMode.HighQuality;

Upvotes: 0

Related Questions