Printing with a Zebra printer produces faint and blurry images

I wrote a library that creates a bitmap with some user input. This bitmap is then printed using a zebra printer. The problem I am facing is all very faint and blurry image printed by a zebra printer, but if I print a bitmap image on a laser printer, it looks completely normal. Has anyone come across this before, and if so, how did they fix it? I have tried almost everything I can think of about printer settings.

Updated with code for how I create bitmaps.

public static Bitmap GenerateLabel<T>(T obj, XmlDocument template)
    {
        try
        {
            int width = Convert.ToInt32(template.SelectSingleNode("/LABELS/@width").Value);
            int height = Convert.ToInt32(template.SelectSingleNode("/LABELS/@height").Value);

            if (obj == null || height <= 0 || width <= 0)
                throw new ArgumentException("Nothing to print");

            Bitmap bLabel = new Bitmap(width, height);
            Graphics g = Graphics.FromImage(bLabel);

            XmlNodeList fieldList = template.SelectNodes("/LABELS/LABEL");

            foreach (XmlNode fieldDetails in fieldList)
            {
                //non important code...

                    g.DrawImage(bBarCode, field.Left, field.Top);


                using (TextBox txtbox = new TextBox())
                {
                    // more non important code...

                    Rectangle r = new Rectangle(field.Left, field.Top, field.Width, field.Height);
                    txtbox.DrawToBitmap(bLabel, r);
                }
            }

            return bLabel;
        }
        catch (Exception ex)
        {
            throw new Exception("Unable to create bitmap: " + ex.Message);
        }
    }
+3
source share
6

Zebra . Zebra, 203 DPI 2- - (1 ).

+5

"" -, , , , .

+2

Thermal SDK, / , Zebra , . , , , , .

+2

1 . . . , - , , . , ( ), ( ):

public static Bitmap BitmapTo1Bpp(Bitmap img)
   {
       int w = img.Width;
       int h = img.Height;

       Bitmap bmp = new Bitmap(w, h, PixelFormat.Format1bppIndexed);
       BitmapData data = bmp.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadWrite, PixelFormat.Format1bppIndexed);

       for (int y = 0; y < h; y++)
       {
           byte[] scan = new byte[(w + 7) / 8];

           for (int x = 0; x < w; x++)
           {
               Color c = img.GetPixel(x, y);
               if (c.GetBrightness() >= 0.5) scan[x / 8] |= (byte)(0x80 >> (x % 8));
           }

           Marshal.Copy(scan, 0, (IntPtr)((int)data.Scan0 + data.Stride * y), scan.Length);
       }

       bmp.UnlockBits(data);

       return bmp;
   }
+2

- - , dpi , , .

intermec thermals,

+1

. Zebra -, -.

#, VB , , :

    ''' <summary>
''' Converts an image to Black and White
''' </summary>
''' <param name="image">Image to convert</param>
''' <param name="Mode">Convertion mode</param>
''' <param name="tolerance">Tolerancia del colores</param>
''' <returns>Converts an image to Black an white</returns>
''' <remarks></remarks>
Public Function PureBW(ByVal image As System.Drawing.Bitmap, Optional ByVal Mode As BWMode = BWMode.By_Lightness, Optional ByVal tolerance As Single = 0) As System.Drawing.Bitmap
    Dim x As Integer
    Dim y As Integer
    If tolerance > 1 Or tolerance < -1 Then
        Throw New ArgumentOutOfRangeException
        Exit Function
    End If
    For x = 0 To image.Width - 1 Step 1
        For y = 0 To image.Height - 1 Step 1
            Dim clr As Color = image.GetPixel(x, y)
            If Mode = BWMode.By_RGB_Value Then
                If (CInt(clr.R) + CInt(clr.G) + CInt(clr.B)) > 383 - (tolerance * 383) Then
                    image.SetPixel(x, y, Color.White)
                Else
                    image.SetPixel(x, y, Color.Black)
                End If
            Else
                If clr.GetBrightness > 0.5 - (tolerance / 2) Then
                    image.SetPixel(x, y, Color.White)
                Else
                    image.SetPixel(x, y, Color.Black)
                End If
            End If
        Next
    Next
    Return image
End Function
+1

Source: https://habr.com/ru/post/1741169/


All Articles