我在 Windows 移动设备上使用 Zebra iMZ320 打印机和 vb.net。用于 MZ320 的代码。
我正在尝试使用 CPCL 打印图形。
私有子 Print_Label()
Try
Dim zebraPrinterConnection As ZebraPrinterConnection = New BluetoothPrinterConnection(MyMacAddress)
zebraPrinterConnection.Open()
Dim printer As ZebraPrinter = ZebraPrinterFactory.GetInstance(zebraPrinterConnection)
cpclData = ""
cpclData = cpclData & "! 0 200 200 300 1" & vbCr & vbLf
cpclData = cpclData & "TEXT 4 0 30 40 This is a CPCL test." & vbCr & vbLf
DrawLogoBitmap(10, 10)
cpclData = cpclData & vbCr & vbLf
cpclData = cpclData & "FORM" & vbCr & vbLf
cpclData = cpclData & "PRINT" & vbCr & vbLf
txt_TestPrint.Text = cpclData
Debug_Output()
' Send the data to printer as a byte array.
zebraPrinterConnection.Write(Encoding.[Default].GetBytes(cpclData))
Thread.Sleep(500)
zebraPrinterConnection.Close()
Catch e As ZebraPrinterConnectionException
Console.Write(e.StackTrace)
End Try
结束子
Public Sub DrawLogoBitmap(ByVal xPosition As Integer, ByVal yPosition As Integer)
Try
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 & (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
Catch ex As Exception
MsgBox("Error - Creating Logo" & vbCrLf & Err.Number & " " & Err.Description, MsgBoxStyle.Critical, "Database Error")
End Try
结束子
公共函数 GetLogo() 作为字符串
Try
Return System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) & "\logo.bmp"
Catch ex As Exception
MsgBox("Error - Locating Logo" & vbCrLf & Err.Number & " " & Err.Description, MsgBoxStyle.Critical, "Image Error")
Return 0
End Try
结束功能
这将为 80px x 80px 位图生成下面的输出 当将 CPCL 代码发送到打印机时,表示已建立链接的蓝灯亮起,但没有打印任何内容。
我可以打印更小的图形,所以正如你所说的 EG 声明有问题,或者刺痛本身太大而无法通过蓝牙发送。
!0 200 200 300 1 TEXT 4 0 30 40 这是 CPCL 测试。