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