Zebra打印机在尝试打印位图时输出HEX

时间:2013-06-18 21:30:43

标签: vb.net windows-mobile hex zebra-printers

我使用的是Zebra iMZ320打印机,Windows移动设备,CPCL和vb.net。

我试图让代码加载位图图像然后使用CPCL打印它

我有一个类似的代码,下面的代码,没有问题。我必须遗漏一些明显的东西,但对于我的生活,我看不到它。

我的问题是打印机只打印输出HEX而不是图像!有没有人遇到过这个?你能帮忙吗?

Public Sub DrawBitmap(ByVal xPosition As Integer,ByVal yPosition As Integer)

Dim bmp As Bitmap bmp = New 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()

End Sub

公共共享函数StrToByteArray(ByVal str As String)As Byte()

Dim encoding As New System.Text.ASCIIEncoding()

Return encoding.GetBytes(str)

结束功能

Private Sub 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

End Sub

如果有帮助,代码会将此文件生成为输出。

! 0 200 200 300 1 EG 10 80 10 10 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF800FFF8001FFFFFFFFFE0001FC00007FFFFFFFF800007000001FFFFFFFF01F80703FF80FFFFFFFE07FF800FFFE07FFFFFFC1FFFC01FFFF87FFFFFFC3FFFC01FFFF83FFFFFF87FFFC01FFFFC3FFFFFF87FFFC11FFFFC3FFFFFF87FFFC39FFFFC1FFFFFF87FFFC7FFFFFC1FFFFFF87FFFCFFFFFFC1FFFFFF87FFFFFFFFFFC1FFFFFFC3FFFFFFFFFFC3FFFFFFC1FFFFFFFFFF83FFFFFFE1FFFFFFFFFF07FFFFFFE1FFFFFFFFFE07FFFFFFE1FFFFFFFFFC0FFFFFFFE1FFFFCF0FF81FFFFFFFC3FFFF8001C03FFFFFFFC3FFCF800000FFFFFFFFC1FF87C04003FFFFFFFFE0FF07FFF81FFFFFFFFFE0780FFFFC3FFFFFFFFFF0001FFFF83FFFFFFFFFFC003FFFF87FFFFFFFFFFF803FFFF87FFFFFFFFFFFFC1FFFF87FFFFFFFFFFFFC1FFFF07FFFFFFFFFFFFE0FFFF0FFFFFFFFFFFFFE0FC020FFFFFFFFFFFFFF000000FFFFFFFFFFFFFF000001FFFFFFFFFFFFFF8001C1FFFFFFFFFFFFFF83E3F9FFFFFFFFFFFFFFCFE3FFFFFFFFFFFFFFFFF9C39FFFFFFFFFFFFFFFF8C70FFFFFFFFFFFFFFFF9879FFFFFFFFFFFFFFFFF8FFFFFFFFFFFFFFFF7FF807FFFFFFFFFFFFFEFFF00FFF7FFFFFFFFFFCFFF03FFF3FFFFFFFFFFCFFFFFFFF3FFFFFFFFFFC FFC001FF3FFFFFFFFFFC7F8000FE3FFFFFFFFFFC1F0000783FFFFFFFFFFC000FF0003FFFFFFFFFFE001FF8007FFFFFFFFFFF003FFC00FFFFF3FFFFFFC07FFF03FFFFE1FFF7FFFFFFFFFFFFFC61FFE0FFFFFFFFFFFFC023FFE01FFFFFFFFFFF803FFFF003FFFFFFFFF0C0FFFFF800FFFFFFFF00C1FFFFF02041FFC7FE00C3FFFFF070000E001E0183FFFFE070400C001F4183FFFFE000F008001FE001FFFFE001F0783C1FE000FFFFC083F0783C1FF0003FFC01C1E0F07E3FF03007FC01E1E0F0700FF83803FE00C1E0F06007F80C07FF0001E0F06007F8043FFFF003E0F83C1FF007FFFFFE0700F83C1FE00FFFFFFFFE0038001FF0FFFFFFFFFF003C001FFFFFFFFFFFFFE03E001FFFFFFFFFFFFFFFFFCFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF PRINT

2 个答案:

答案 0 :(得分:0)

iMZ打印机预先配置为在线模式。您必须将其更改为zpl模式,以便它可以解析zpl或cpcl

发送此SGD以更改打印机的语言。

! U1 setvar“device.languages”“zpl”

答案 1 :(得分:0)

您将位图转换为十六进制字符串

  cpclData = cpclData & (currentValue.ToString("X2"))

然后将其编码为byte []

 Return encoding.GetBytes(str)

结束将数据发送到打印机:

thePrinterConn.Write(StrToByteArray(cpclData))

但我假设您必须将十六进制数据字符串编码回一个字节数组,并将相应的十六进制值转换回一个字节。例如,十六进制字符串“FFFFFFFF”必须转换回byte [] {0xff,0xff,0xff,0xff},exxcpet打印机语言(CPCL?)读取十六进制字符串数据并将其转换回字节本身。