印刷质量Winform [英] printing quality winform

查看:63
本文介绍了印刷质量Winform的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试从WinForms应用程序打印时,我遇到2个问题。首先是质量很差,无论我尝试什么。第二个是我从左上角开始有很大的页边距,而winform正在剪切。有任何想法吗?这是我的代码:

I have 2 problems while trying to print from a WinForms application. The first is a very very bad quality no matter what I try. The second is that I have a big page margin from the top left corner and the winform is cutting. Any ideas? This is my code:

Bitmap MemoryImage;
    public void GetPrintArea(Panel pnl)
    {
        MemoryImage = new Bitmap(pnl.Width, pnl.Height);
        Rectangle rect = new Rectangle(0, 0, pnl.Width, pnl.Height);
        pnl.DrawToBitmap(MemoryImage, new Rectangle(0, 0, pnl.Width, pnl.Height));
    }
    protected override void OnPaint(PaintEventArgs e)
    {
        if (MemoryImage != null)
        {
            e.Graphics.DrawImage(MemoryImage, 0, 0);
            base.OnPaint(e);
        }
    }
    void printdoc1_PrintPage(object sender, PrintPageEventArgs e)
    {
        e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
        e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
        e.Graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
        Rectangle pagearea = e.PageBounds;
        e.Graphics.DrawImage(MemoryImage, (pagearea.Width / 2) - (this.panel1.Width / 2), this.panel1.Location.Y);

    }
    public void Print(Panel pnl)
    {
        panel1 = pnl;
        GetPrintArea(pnl);
        printPreviewDialog1.Document = printdoc1;
        printPreviewDialog1.ShowDialog();
    }
    private void button2_Click(object sender, EventArgs e)
    {
        Print(this.panel1);
    }


推荐答案

再次。尽管最终该问题可能会消失,但没有魔术解决方案。 视网膜显示器的出现是至关重要的。

This comes up over and over again. There just is no magic solution, although eventually the problem is likely to disappear. The emergence of "retina" displays is pivotal.

核心问题是显示器的分辨率比打印机的分辨率差得多。典型的打印机具有每英寸600点的分辨率。这使其能够在一张纸上打印6600 x 5100单个像素。全高清监视器的分辨率远远超过监视器所能显示的水平,最高可达1920 x 1080像素。付出或接受,大约要差5倍。

The core issue is that monitors have a resolution that's drastically worse than printers. A typical printer has a resolution of 600 dots per inch. Which makes it capable of printing 6600 x 5100 individual pixels on a piece of paper. Much, much more than what a monitor can display, a full HD monitor tops out at 1920 x 1080 pixels. Roughly a factor of 5 worse, give or take.

当您在一张纸上打印监视器上显示的内容并尝试将其保留时,效果不佳。一样的大小。不可避免地,由于监视器上缺少像素,因此监视器上的每个像素都作为5x5斑点打印在纸上。如果您尝试使像素保持一一对应,则在纸上获得清晰的副本。

This works out poorly when you print what shows up on a monitor on a piece of paper and try to keep it the same size. Inevitably, because of the lack of pixels on the monitor, each one pixel from the monitor is printed as a 5x5 blob on paper. If you try to keep the pixel mapping one-to-one, you will get a razor-sharp copy on paper. But it has turned into a postage-stamp.

不可避免地,由于这些像素斑点,打印输出看起来非常粗糙。看起来特别糟糕的是 text 。操作系统使用许多技巧来使文本在分辨率较差的监视器上看起来不错。抗锯齿是标准配置,ClearType之类的技巧旨在利用显示器物理特性来帮助提高感知分辨率。当打印文本时,这不再起作用,那些抗锯齿像素变成斑点并变得非常明显,从而完全破坏了效果。对于彩色打印机上的ClearType文本尤其不利,现在可以清楚地看到红色和蓝色条纹。

Inevitably, the printout looks very grainy due those pixel blobs. What looks especially poor is text. Operating systems use lots of tricks to make text look good on monitors with poor resolution. Anti-aliasing is standard, tricks like ClearType were designed to take advantage of monitor physics that can help increase the perceived resolution. This no longer works when the text is printed, those anti-aliasing pixels turn into blobs and become very visible, completely ruining the effect. Especially bad for ClearType text on a color printer, the red and blue color fringes now can be clearly seen.

唯一可行的方法是使用实​​际分辨率而不是显示器分辨率。就像在.NET中使用PrintDocument类一样。使用报告生成器可以帮助避免为它编写代码。

The only decent approach is to render to a printer using the actual resolution and not the monitor resolution. Like using the PrintDocument class in .NET. Using a report generator can help avoid having to write the code for it.

这篇关于印刷质量Winform的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆