当前位置: 首页 > 知识库问答 >
问题:

斑马打印机输出HEX当尝试打印位图

淳于博
2023-03-14

我正在使用Zebra iMZ320打印机、windows mobile设备、CPCL和vb.net。

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

我有一段类似于下面的代码,可以毫无问题地工作。我一定错过了一些显而易见的东西,但就我的一生而言,我看不到它。

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

公共子绘制位图(ByVal xPosition为整数,ByVal yPosition为整数)

Dim bmp As Bitmap bmp=新系统.绘图.位图(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作为字符串)作为Byte()

Dim encoding As New System.Text.ASCIIEncoding()

Return encoding.GetBytes(str)

结束函数

私人Sub Print_发票()

' 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 10ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7FFFFFC1FFFFF87FFFCFFFFFFC1FFFFFFFF87FFFFFFFFFFFFFFFFC1FFFFFFFFC3FFFFFFFFFFFFFFC3FFFFFFFFFFC1FFFFFFFFFFFFFF83FFFfffe1fffffffffff07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffFFFE0FC020FFFFFFFFFF000000FFFFFFFFFFFFFFFF000001FFFFFFFFFFFFFFFF8001C1FFFFFFFFFFFFFFFFFFF83E3F9FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9C39FFFFFFFFFFFFFFFFFFFFFFFFFF8C70FFFFFFFFFFFFFFFFFFFFFFFF9879FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF03FFC00FFFFF3FFFFC07FFF03FFFFFFF1FF7FFFFFFFFFFFFFC61FF0FFFFFFFFFFFFFFC023FF01FFFFFFFFFFFFF803FFFF003FFFFFFFFFFFFF0C0FFFFF 800FFFFFF00C1FFFFF02041FFFC7FE00C3FFFFF0700000E001E0183FFFFFFE07040C001F4183FFFF000F008001FE001FFFFFF001F0783C1FE000FFFFC083F0783C1FF0003FFC01C1E0F07E3FF03007FC01E1E0700FF83803FE00C1E0600F06007F80CF0001E06007F8043FFFFFF003E0F83C1FFFFFF0000FFFFFF000300FFFFFF000300FFFFFFFFFFC001FFFFFFFFFFFFFFF003FF01FFFFFFFFFFFFFFE001FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF打印

共有2个答案

谭宏盛
2023-03-14

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

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

然后将其编码为字节[]

 Return encoding.GetBytes(str)

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

thePrinterConn.Write(StrToByteArray(cpclData))

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

伍耀
2023-03-14

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

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

! U1 setvar“device.languages”“zpl”

 类似资料:
  • 使用JasperReport生成图像,然后尝试在Zebra打印机GC420T上打印该图像。生成图像但不打印。我已经重新检查了连接和端口。我读过这个SO链接和校准一个,但没有工作。 代码: 我阅读了EPL 2手册,并将图像转换为二进制图形数据,以便立即打印。 代码: 在将图像转换成二进制图形数据后,它就不打印数据了。 如何让打印机打印图像?

  • 我们刚从brother标签打印机转移到zebra,c的brother sdk有点像meh,但它实现了我想要的功能。基本上,它让我可以选择在设计器中创建一个标签,并将参考名称附加到文本文件、条形码文件等。然而,看看zebra,我似乎找不到这样做的方法。我不喜欢这样一个事实,即你必须使用他们的设计器设计标签,而他们的设计器没有这个功能,或者用c语言百分之百地设计标签,这阻止了我们的设计器以后重新设计标

  • 07-23 18:11:16.752:E/AndroidRuntime(15071):java.lang.UnsatisfiedLinkError:无法从加载器Dalvik.System.PathClassLoader加载createdata[[zip文件“/data/app/com.splan.android-1.apk”],NativeLibraryDirectories=[/data/app

  • 问题内容: 我是一个相对较新的程序员,所以这可能是一个非常简单的问题,但是让我有些困惑。 我正在尝试将Java GUI的最终输出打印到打印机。现在,在我的GUI中,有了它,当您单击打印时,会弹出一个弹出窗口,列出可用的打印机,并根据您选择的打印机,将其打印到该打印机。 但是事实并非如此。我通过搜索互联网来解决此问题,从而获得了大部分代码,并找到了一些很有前途的代码。但是,它是从文件打印出来的。因此

  • 编辑:所以在一天的混乱之后。我的问题是spintf。我最初认为我的循环是错误的。

  • 4.12. 打印输出 前面例子中涉及到的打印都比较简单。在这一节中,我们将要讨论Go语言格式化输出的功能。 我们已经用过"fmt"包中的"Printf"和"Fprintf"等输出函数。"fmt"包中的"Printf"函数的 完整说明如下: Printf(format string, v ...) (n int, errno os.Error) 其中"..."表示数目可变参数,