views:

75

answers:

3

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);
        }
A: 

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

Mamta Dalal
No difference unfotunately
Jon
Note that for printing antialiasing is a bad idea, usually since you get worse results due to dithering.
Joey
+1  A: 

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.

Rune Grimstad
My screen resolution is 1920x1080 so the resolution should be ok? Would not using the Bitmap class be any better?
Jon
As Hans commented above, your screen resolution is much lower than your printers resolution and that is the reason of the low quality.
Rune Grimstad
With not using a bitmap do you mean to use an Image instead? It will end up with the same result. If you want to improve the quality you cannot use the Form printing method you use today.
Rune Grimstad
+1  A: 

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.

Hans Passant
I agree but I cant use Crystal Reports in this scenario.
Jon
Well, draw with e.Graphics. It will look great and you can present the info in a format that's much more suitable for paper. Portrait mode and no unsightly blobs of colors.
Hans Passant