Printing / Graphics Problems

Language: VB.NET 2010 Win Form

Scope: I have developed a label printing program designed to print custom labels on a zebra printer. I had problems with clarity from the printer when I tried to print the entire label as an image, so I try to save all the text from the labels to an array, clear the labels, send the remaining image to the printer and overlay the new text based on the saved array. This result is intended to send text to the printer, not images.

Problem: The resulting label is very clear for the text, because I want it, however, I had alignment problems for my printing method. For tests, I have a source image that displays with an inscription on top, on which they should align perfectly or close for reasonable reasons. Moreover, the result is that they are not aligned.

Testing:

Dim g2 As Graphics g2 = Form1.PictureBox2.CreateGraphics g2.CompositingQuality = Drawing2D.CompositingQuality.HighQuality g2.SmoothingMode = Drawing2D.SmoothingMode.HighQuality g2.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic g2.Clear(Color.White) g2.DrawImage(largeimage, New Point(0, 0)) Dim myBrush As Brush Dim i As Integer = 0 Do Until i = label_array.Count - 1 myBrush = New SolidBrush(label_array(i).ForeColor) g2.DrawString(label_array(i).Text, label_array(i).Font, myBrush, label_array(i).Location) i = i + 1 Loop 

As part of the printing method, I used the above method to display the overlay and image in the image window. At the same time, it WORKS, however ...

  e.Graphics.CompositingQuality = Drawing2D.CompositingQuality.HighQuality e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic e.Graphics.Clear(Color.White) e.Graphics.DrawImage(largeimage, New Point(0, 0)) i = 0 Do Until i = label_array.Count - 1 myBrush = New SolidBrush(label_array(i).ForeColor) e.Graphics.DrawString(label_array(i).Text, label_array(i).Font, myBrush, label_array(i).Location) i = i + 1 Loop 

.. doing this on the print graph shown above leads to misalignment ...

Any ideas are welcome as I will try anything. I assume that graphic printing does something extra from normal graphics, which I don't know about.


I noticed that TextRenderer.DrawText improves the results compared to DrawString. However, when using this, the result seems to scale from the original using an unknown scaling factor ...

The following is an overlay on top of the original: enter image description here

+4
source share
2 answers

You re-open the well-known issue with Graphics.DrawString (), this is not true. The most obvious demonstration of this problem is this form of the Winforms form:

 public partial class Form1 : Form { public Form1() { InitializeComponent(); } protected override void OnPaint(PaintEventArgs e) { e.Graphics.DrawString("Hiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii", this.Font, Brushes.Black, 0, 0); } } 

Which looks like this:

enter image description here

No magic will ever force you to overlap on the part of the line where the distance between the letters me suddenly changes. GDI + was Microsoft's first attempt to allow independent text rendering, and that didn't work. This is in a good company, WPF was the second attempt, and it had a lot of flacks for fuzzy output. Solved in a way that looked like a way to fix it in .NET 2.0 for Winforms, you should always render the text in the window using TextRenderer.DrawText (). Which does not make an attempt to make the displayed text scale smoothly, he always prefers to set the pixel grid. Same thing with WPF ideal vs display rendering mode, added in .NET 4 .

There are significant other problems with your approach; the way you render text is significantly unsuitable for the printer. You can see that when you zoom in, you can see pixels, for this it is useful to use the ZoomIt SysInternals utility. I increased the letter a on the right side of the graph:

enter image description here

Notice the reddish and bluish pixels at the edge of the letter. This is a smoothing method called ClearType , it improves the perceived resolution of LCD monitors. It works only on LCD panels; it does not work on a printer that does not have the same strip pattern. On paper, the letter will just look fuzzy with colored fringe. Although this is not so bad on the Zebra printer, as it does not support color printing.

These are artifacts specific to displaying text on a monitor, devices that have a fairly low resolution. Fixing a pixel grid and ClearType are tricks to make text look decent. Typical monitors have a maximum of 120 pixels per inch. Although this is finally improving with Apple by clicking on the "mesh" displays. A company that is interested in high-resolution monitors has traditionally provided text in β€œperfect” mode .

These rendering tricks are completely unsuitable for the printer, a device with a much higher resolution. 600 pixels per inch typical, easily 5 times better than a monitor. When you draw photo paper on the printer, you really spend on the improvements you get when you connect directly to the printer. Their difference is very important and easy to see with the naked eye. The text looks much nicer and clearer when you make text with a resolution of 600 dpi. The text, which was originally submitted for 120 dpi and enlarged for the printer, looks like "blobby" and "raw."

Always use the PrintDocument class to draw on a printer.

+2
source

Once upon a time, I wrote a label printing application for a Zebra printer, so maybe I can help. That day, we had only the ZPL2 API, and only printed text and simple graphics, none of these images. Anyway...

My suspicion is that this is a scaling issue. This might explain why your original image is fuzzy - maybe the printer automatically tries to scale it to fit the label and does a bad job? And of course, this explains the labels above.

What strikes me in your code above is how you get the Graphics object. One comes from a box of pictures; another, presumably from the printer. Keep in mind that the Graphics object is device dependent. That is, the properties and methods of printing them depend on whether you are printing a specific control (different controls may have different scaling) or a specific printer.

Have you tried to use the existing code for printing on a laser printer? It may be interesting to see the results. Also see Graphics Properties, such as ScaleTransform.

+1
source

All Articles