Note that there are some explanatory texts on larger screens.

plurals
  1. POPrinting / Graphics Problems
    text
    copied!<p><strong>Language:</strong> VB .NET 2010 Win Form</p> <p><strong>Scope:</strong> I have developed a label printing program that is intended to print custom labels to a zebra printer. I was having problems with clarity from the printer when I tried to print the entire label as an image therefore I am trying to store all of the text from labels to an array, clear the labels out, send the leftover image to the printer, and overlay new text based on the stored array. This result is intended to send text to the printer rather than an image.</p> <p><strong>Problem:</strong> The resulting label is very clear for the text as I want it however I was having troubles with alignment for my printing method. For tests I have the original image being displayed with the overlay text on top to which they should align perfectly or close within reason. When doing this the result is that they are not aligned.</p> <p><strong>Testing:</strong></p> <pre><code> 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 </code></pre> <p>Within the printing method I used the above method to output the overlay and image to a picture box. When doing this it WORKS, however...</p> <pre><code> 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 </code></pre> <p>..doing it to the printing graphic shown above results in misalignment...</p> <p>Any ideas are welcome as I will try about anything. I am guessing that the printing graphic is doing something additional from a normal graphic that I am not aware of.</p> <hr> <p>I did notice that TextRenderer.DrawText improves results compared to DrawString. However when using this the result seems to be scaled from the original by some unknown scaling factor... </p> <p>Below is the resulting overlay on top of the original: <img src="https://i.stack.imgur.com/gHxFB.png" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload