打印到Zebra打印机会产生模糊和模糊的图像

我写了一个库,它从一些用户输入创建一个位图图像。 然后使用斑马打印机打印该位图。 我遇到的问题是斑马打印机打印的图像上的一切都非常微弱和模糊,但如果我将位图打印到激光打印机,它看起来很正常。 有没有人遇到这个,如果是这样,他们是如何解决它的? 我已经尝试了几乎所有我能想到的打印机设置。

更新了我如何创建位图图像的代码。

public static Bitmap GenerateLabel(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); } } 

Zebra打印驱动程序使输出抖动。 要为Zebra打印创建完美图像,您需要创建203 DPI和2色黑白(1位)的图像。

这是所有斑马打印机中的通用“function”,驱动程序在传输到打印机本身之前使用有损技术压缩图像,据我所知,没有解决方法。

我最终使用名为Thermal SDK的第三方库,它允许我绘制/保存我的位图,然后以所需的“特殊”格式将其发送到斑马打印机。 它适用于单个标签,但如果你想一次做很多,那么效率会相当低,因为你必须先将每个标签保存到文件中才能打印出来。

打印机需要1 bpp的单色图像。 并且没有用于将彩色或灰度图像转换为单色的完美算法。 取决于图像,这些算法可能会或可能不会产生良好的结果。 因此,最好的方法是从一开始就将图像准备为单色,就像上面提到的Mike Ransom一样。 但如果必须以编程方式完成,初始彩色图像应仅使用黑白颜色(以便转换产生良好的结果),然后您可以使用这样的算法( 源链接在这里 ):

 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; } 

一旦看到的地方是驱动程序设置,打印机上的dpi是什么,有许多设置可能导致效果,而不仅仅是有损技术。

我们已经发送了许多位图图像到zebras和intermec thermals它应该工作

答案很简单。 Zebra打印机仅打印黑白,因此在将图像发送到打印机之前,请将其转换为黑白。

我不是C#编码器,但VB代码看起来很相似所以我希望他的帮助:

  '''  ''' Converts an image to Black and White '''  ''' Image to convert ''' Convertion mode ''' Tolerancia del colores ''' Converts an image to Black an white '''  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