1

I am using a Zebra iMZ320 printer, a windows mobile device, CPCL and vb.net.

I am trying to get the code to load a bitmap image and then to print this using CPCL

I have previoulsy had a similar piece of code to that contaibed below working with no issue. I must be missing something obvious, but for the life of me I cannot see it.

My problem is the printer will only printout HEX instead of the image ! Has anyone come across this before ? Can you help ?

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

Public Shared Function StrToByteArray(ByVal str As String) As Byte()

Dim encoding As New System.Text.ASCIIEncoding()

Return encoding.GetBytes(str)

End Function

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

The code produce this file as output if it helps.

! 0 200 200 300 1 EG 10 80 10 10 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF800FFF8001FFFFFFFFFE0001FC00007FFFFFFFF800007000001FFFFFFFF01F80703FF80FFFFFFFE07FF800FFFE07FFFFFFC1FFFC01FFFF87FFFFFFC3FFFC01FFFF83FFFFFF87FFFC01FFFFC3FFFFFF87FFFC11FFFFC3FFFFFF87FFFC39FFFFC1FFFFFF87FFFC7FFFFFC1FFFFFF87FFFCFFFFFFC1FFFFFF87FFFFFFFFFFC1FFFFFFC3FFFFFFFFFFC3FFFFFFC1FFFFFFFFFF83FFFFFFE1FFFFFFFFFF07FFFFFFE1FFFFFFFFFE07FFFFFFE1FFFFFFFFFC0FFFFFFFE1FFFFCF0FF81FFFFFFFC3FFFF8001C03FFFFFFFC3FFCF800000FFFFFFFFC1FF87C04003FFFFFFFFE0FF07FFF81FFFFFFFFFE0780FFFFC3FFFFFFFFFF0001FFFF83FFFFFFFFFFC003FFFF87FFFFFFFFFFF803FFFF87FFFFFFFFFFFFC1FFFF87FFFFFFFFFFFFC1FFFF07FFFFFFFFFFFFE0FFFF0FFFFFFFFFFFFFE0FC020FFFFFFFFFFFFFF000000FFFFFFFFFFFFFF000001FFFFFFFFFFFFFF8001C1FFFFFFFFFFFFFF83E3F9FFFFFFFFFFFFFFCFE3FFFFFFFFFFFFFFFFF9C39FFFFFFFFFFFFFFFF8C70FFFFFFFFFFFFFFFF9879FFFFFFFFFFFFFFFFF8FFFFFFFFFFFFFFFF7FF807FFFFFFFFFFFFFEFFF00FFF7FFFFFFFFFFCFFF03FFF3FFFFFFFFFFCFFFFFFFF3FFFFFFFFFFCFFC001FF3FFFFFFFFFFC7F8000FE3FFFFFFFFFFC1F0000783FFFFFFFFFFC000FF0003FFFFFFFFFFE001FF8007FFFFFFFFFFF003FFC00FFFFF3FFFFFFC07FFF03FFFFE1FFF7FFFFFFFFFFFFFC61FFE0FFFFFFFFFFFFC023FFE01FFFFFFFFFFF803FFFF003FFFFFFFFF0C0FFFFF800FFFFFFFF00C1FFFFF02041FFC7FE00C3FFFFF070000E001E0183FFFFE070400C001F4183FFFFE000F008001FE001FFFFE001F0783C1FE000FFFFC083F0783C1FF0003FFC01C1E0F07E3FF03007FC01E1E0F0700FF83803FE00C1E0F06007F80C07FF0001E0F06007F8043FFFF003E0F83C1FF007FFFFFE0700F83C1FE00FFFFFFFFE0038001FF0FFFFFFFFFF003C001FFFFFFFFFFFFFE03E001FFFFFFFFFFFFFFFFFCFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF PRINT

4

2 回答 2

0

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

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

!U1 setvar "device.languages" "zpl"

于 2013-06-19T00:55:11.920 回答
0

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

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

然后将其编码为 byte[]

 Return encoding.GetBytes(str)

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

thePrinterConn.Write(StrToByteArray(cpclData))

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

于 2013-06-20T03:56:34.523 回答