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: 