简体   繁体   中英

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

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.

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.

试试这个:e.Graphics.SmoothingMode = SmoothingMode.HighQuality;

You can increase the Dbi resolution. Default is 96

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM