在TSC打印机上打印位图 [英] Printing a bitmap on a TSC printer
问题描述
我尝试通过OTG使用android设备在tsc tdp-225 printer
上打印图像.
I try to print image on tsc tdp-225 printer
using the android device via OTG.
这是来自文档的示例,用于在tsc printer
上打印简单的位图图像
.
This is example from documentation for printing simple bitmap image on tsc printer
.
这是我的实现 .
这就是打印机的打印内容
And this is what the printer has printed
也许有人已经遇到了这个问题.使用PUTBMP打印单色位图也不起作用.
Maybe someone has already encountered this problem. Printing a monochromatic bitmap using PUTBMP also does not work.
推荐答案
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将位图上传到打印机的问题.
I should convert hex string to byte array. Anyway propblem with printing via PUTBMP command is still exists. Propblem with uploading bitmap to printer with command DOWNLOAD F.
更新
如果仍然有用,我将使用以下实现来打印位图图像
If it is still relevant, I use the following implementation for printing bitmap image
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())
}
前两个命令是预备命令.第三条命令逐像素打印位图
The first two commands are preparatory. Third command prints a bitmap pixel by pixel
这篇关于在TSC打印机上打印位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!