问题
I try to print image on tsc tdp-225 printer
using the android device via OTG.
This is example from documentation for printing simple bitmap image on tsc printer
This is my implementation
.And this is what the printer has printed
Maybe someone has already encountered this problem. Printing a monochromatic bitmap using PUTBMP also does not work.
回答1:
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
}
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.
UPDATE
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
来源:https://stackoverflow.com/questions/48497617/printing-a-bitmap-on-a-tsc-printer