views:

564

answers:

5

I wrote a library which creates a bitmap image from some user input. This bitmap is then printed using a zebra printer. The problem I am running into is everything is very faint and blurry on the image printed by the zebra printer but if I print the bitmap to a laser printer it looks perfectly normal. Has anyone run into this before and if so how did they fix it? I have tried nearly everything I can think of printer settings wise.

Updated with code for how I create the bitmap images.

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);
        }
    }
A: 

This is a universal 'feature' among all zebra printers, the drivers compress the images using a lossy technique before transmission to the printer itself, there is no workaround as far as I can tell.

Lewis
A: 

once place to look at is the driver settings, what is the dpi on the printer, there are many settings that can be causing the effect not just the lossy technique.

we've sent many bitmap images to zebras and intermec thermals it should work

Bernie
A: 

I ended up using a third party library called Thermal SDK which allowed me to draw/save my bitmap and then send it to the zebra printer in the 'special' format it needed. It works for single labels but if you wanted to do many at a time it would be pretty inefficient since you have to save each label to a file before you can print it.

Nathan
This is not necessary. I print to Zebra printers all the time, using the Windows API directly. Copying a bitmap to the printer is trivial, if you've created the bitmap properly.
Mark Ransom
Mark, please see my initial post, I have updated with my bitmap creation method.
Nathan
A: 

The Zebra print driver is dithering your output. To create a perfect image for Zebra printing, you'll need to create an image at 203 DPI and 2-color black and white (1-bit).

Mark Ransom
+1  A: 

Answer is easy. Zebra printers only prints Black and White, so before you send the image to the printer, convert it to black and white.

I'm not a C# coder but VB code looks similar so I hope his helps:

    ''' <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
xolast
OMG, SetPixel in this context is about as slow as it gets! A better approach would be to draw the image in normal color on a bitmap, then convert the whole bitmap to grayscale or a dithered black and white image. This article has some sweet, fast algorithms (the latter two are 188ms an 62ms running time) to convert to grayscale: http://www.switchonthecode.com/tutorials/csharp-tutorial-convert-a-color-image-to-grayscale
jrista