打印质量winform [英] printing quality winform

查看:24
本文介绍了打印质量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天全站免登陆