Printing a bitmap on a TSC printer

假如想象 提交于 2020-01-06 07:42:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!