Zebra 打印机在尝试打印位图时输出 HEX
Posted
技术标签:
【中文标题】Zebra 打印机在尝试打印位图时输出 HEX【英文标题】:Zebra Printer Outputing HEX when trying to print a bitmap 【发布时间】:2013-06-15 06:49:30 【问题描述】:我正在使用 Zebra iMZ320 打印机、Windows 移动设备、CPCL 和 vb.net。
我正在尝试获取代码以加载位图图像,然后使用 CPCL 进行打印
我以前有一段与下面包含的代码类似的代码,没有问题。我一定错过了一些明显的东西,但对于我的生活,我看不到它。
我的问题是打印机只会打印十六进制而不是图像!有没有人遇到过这个?你能帮忙吗?
Public Sub DrawBitmap(ByVal xPosition As Integer, ByVal yPosition As Integer)
将 bmp 调暗为位图 bmp = 新 System.Drawing.Bitmap(GetLogo)
If bmp Is Nothing Then
Throw New ArgumentNullException("bmp")
End If
'Make sure the width is divisible by 8
Dim loopWidth As Integer = 8 - (bmp.Width Mod 8)
If loopWidth = 8 Then
loopWidth = bmp.Width
Else
loopWidth += bmp.Width
End If
cpclData = ""
cpclData = cpclData & "! 0 200 200 300 1 " & vbCr & vbLf
cpclData = cpclData & (String.Format("EG 0 1 2 3 ", loopWidth \ 8, bmp.Height, xPosition, yPosition))
For y As Integer = 0 To bmp.Height - 1
Dim bit As Integer = 128
Dim currentValue As Integer = 0
For x As Integer = 0 To loopWidth - 1
Dim intensity As Integer
If x < bmp.Width Then
Dim color As Color = bmp.GetPixel(x, y)
Dim MyR As Integer = color.R
Dim MyG As Integer = color.G
Dim MyB As Integer = color.B
intensity = 255 - ((MyR + MyG + MyB) / 3)
Else
intensity = 0
End If
If intensity >= 128 Then
currentValue = currentValue Or bit
End If
bit = bit >> 1
If bit = 0 Then
cpclData = cpclData & (currentValue.ToString("X2"))
bit = 128
currentValue = 0
End If
'x
Next
Next
'y
cpclData = cpclData & vbCr & vbLf
cpclData = cpclData & "PRINT"
Print_Invoice()
结束子
公共共享函数 StrToByteArray(ByVal str As String) As Byte()
Dim encoding As New System.Text.ASCIIEncoding()
Return encoding.GetBytes(str)
结束函数
私有子 Print_Invoice()
' Instantiate a connection
Dim thePrinterConn As ZebraPrinterConnection = New BluetoothPrinterConnection(MyMacAddress)
' Open the connection - physical connection is established here.
thePrinterConn.Open()
' Send the data to the printer as a byte array
thePrinterConn.Write(StrToByteArray(cpclData))
' Make sure the data got to the printer before closing the connection
Thread.Sleep(500)
' Close the connection to release resources.
thePrinterConn.Close()
' Debug output
txt_TestPrint.Text = cpclData.ToString
Dim objStreamWriter As StreamWriter
Dim file_name As String
'open dialog box for new file
SaveFileDialog1.InitialDirectory = "\Storage Card\"
If SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
file_name = SaveFileDialog1.FileName
If Len(file_name) > 0 Then
objStreamWriter = New StreamWriter(file_name & ".txt")
'Write a line of text from list box.
objStreamWriter.WriteLine(txt_TestPrint.Text)
'Close the file.
objStreamWriter.Close()
Exit Sub
End If
End If
结束子
如果有帮助,代码会生成此文件作为输出。
! 0 200 200 300 1 EG 10 80 10 10 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF800FFF8001FFFFFFFFFE0001FC00007FFFFFFFF800007000001FFFFFFFF01F80703FF80FFFFFFFE07FF800FFFE07FFFFFFC1FFFC01FFFF87FFFFFFC3FFFC01FFFF83FFFFFF87FFFC01FFFFC3FFFFFF87FFFC11FFFFC3FFFFFF87FFFC39FFFFC1FFFFFF87FFFC7FFFFFC1FFFFFF87FFFCFFFFFFC1FFFFFF87FFFFFFFFFFC1FFFFFFC3FFFFFFFFFFC3FFFFFFC1FFFFFFFFFF83FFFFFFE1FFFFFFFFFF07FFFFFFE1FFFFFFFFFE07FFFFFFE1FFFFFFFFFC0FFFFFFFE1FFFFCF0FF81FFFFFFFC3FFFF8001C03FFFFFFFC3FFCF800000FFFFFFFFC1FF87C04003FFFFFFFFE0FF07FFF81FFFFFFFFFE0780FFFFC3FFFFFFFFFF0001FFFF83FFFFFFFFFFC003FFFF87FFFFFFFFFFF803FFFF87FFFFFFFFFFFFC1FFFF87FFFFFFFFFFFFC1FFFF07FFFFFFFFFFFFE0FFFF0FFFFFFFFFFFFFE0FC020FFFFFFFFFFFFFF000000FFFFFFFFFFFFFF000001FFFFFFFFFFFFFF8001C1FFFFFFFFFFFFFF83E3F9FFFFFFFFFFFFFFCFE3FFFFFFFFFFFFFFFFF9C39FFFFFFFFFFFFFFFF8C70FFFFFFFFFFFFFFFF9879FFFFFFFFFFFFFFFFF8FFFFFFFFFFFFFFFF7FF807FFFFFFFFFFFFFEFFF00FFF7FFFFFFFFFFCFFF03FFF3FFFFFFFFFFCFFFFFFFF3FFFFFFFFFFC FFC001FF3FFFFFFFFFFC7F8000FE3FFFFFFFFFFC1F0000783FFFFFFFFFFC000FF0003FFFFFFFFFFE001FF8007FFFFFFFFFFF003FFC00FFFFF3FFFFFFC07FFF03FFFFE1FFF7FFFFFFFFFFFFFC61FFE0FFFFFFFFFFFFC023FFE01FFFFFFFFFFF803FFFF003FFFFFFFFF0C0FFFFF800FFFFFFFF00C1FFFFF02041FFC7FE00C3FFFFF070000E001E0183FFFFE070400C001F4183FFFFE000F008001FE001FFFFE001F0783C1FE000FFFFC083F0783C1FF0003FFC01C1E0F07E3FF03007FC01E1E0F0700FF83803FE00C1E0F06007F80C07FF0001E0F06007F8043FFFF003E0F83C1FF007FFFFFE0700F83C1FE00FFFFFFFFE0038001FF0FFFFFFFFFF003C001FFFFFFFFFFFFFE03E001FFFFFFFFFFFFFFFFFCFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 打印
【问题讨论】:
【参考方案1】:将位图转换为十六进制字符串
cpclData = cpclData & (currentValue.ToString("X2"))
然后将其编码为字节[]
Return encoding.GetBytes(str)
结束将数据发送到打印机:
thePrinterConn.Write(StrToByteArray(cpclData))
但我假设您必须将十六进制数据字符串编码回字节数组,并将对应的十六进制值转换回字节。例如,必须将“FFFFFFFF”的十六进制字符串转换回字节[]0xff,0xff,0xff,0xff,exxcpet 打印机语言(CPCL?)读取十六进制字符串数据并将其转换回字节本身。
【讨论】:
【参考方案2】:iMZ 打印机预先配置为行模式。您必须将其更改为 zpl 模式,以便它可以解析 zpl 或 cpcl
发送此 SGD 以更改打印机的语言。
! U1 setvar "device.languages" "zpl"
【讨论】:
谢谢你成功了。我仍然没有让它正常工作,但我会发布另一个问题来解决这个问题。以上是关于Zebra 打印机在尝试打印位图时输出 HEX的主要内容,如果未能解决你的问题,请参考以下文章
通过 PrintServer 将原始 ZPL 发送到 Zebra 打印机不起作用
Zebra EM 220,使用 Android 打印 Code 128 条码