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
サブ終了
Public Function GetLogo() As String
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ステートメントに何か問題があるか、スティング自体が大きすぎてBluetooth経由で送信できません.
! 0 200 200 300 1 TEXT 4 0 30 40 これは CPCL テストです。