【发布时间】:2018-01-29 09:04:38
【问题描述】:
我尝试通过 OTG 使用 android 设备在 tsc tdp-225 printer 上打印图像。
这是在tsc printer 上打印简单位图图像的文档示例
.
这是我的实现 。
这就是打印机打印的内容
也许有人已经遇到过这个问题。使用 PUTBMP 打印单色位图也不起作用。
【问题讨论】:
标签: android printing bitmap thermal-printer tspl
我尝试通过 OTG 使用 android 设备在 tsc tdp-225 printer 上打印图像。
这是在tsc printer 上打印简单位图图像的文档示例
.
这是我的实现 。
这就是打印机打印的内容
也许有人已经遇到过这个问题。使用 PUTBMP 打印单色位图也不起作用。
【问题讨论】:
标签: android printing bitmap thermal-printer tspl
fun String.hexStringToByteArray(): ByteArray {
val hexStr = this.replace("-", "")
var result = ByteArray(hexStr.length / 2, {0})
for(i in 0 until hexStr.length step 2) {
val hex = hexStr.substring(i, i + 2)
val byte: Byte = Integer.valueOf(hex, 16).toByte()
Log.d(TAG, "hex: $hex; byte: $byte\n")
result[ i / 2] = byte
}
return result
}
我应该将十六进制字符串转换为字节数组。无论如何,通过 PUTBMP 命令打印的问题仍然存在。使用 DOWNLOAD F 命令将位图上传到打印机时出现问题。
更新
如果它仍然相关,我使用以下实现来打印位图图像
fun bitmapCommand(byteArray: ByteArray) {
_connectionManager.sendMessage("CLS\n\r".toByteArray())
_connectionManager.sendMessage("BITMAP 0,0,${_labelWidthPxl / 8},$_labelHeightPxl,0,".toByteArray())
_connectionManager.sendMessage(byteArray)
_connectionManager.sendMessage("\n\r".toByteArray())
_connectionManager.sendMessage("PRINT 1,1\n\r".toByteArray())
}
前两个命令是准备性的。第三个命令逐像素打印位图
【讨论】:
sendcommand?