在蓝牙热敏打印机上打印条形码

时间:2019-04-08 09:24:10

标签: android bluetooth barcode thermal-printer

我正在使用蓝牙热敏打印机,并且能够打印普通文本和发票。但是我无法打印条形码。

我正在使用ZXING库生成条形码

OutputStream os = mBluetoothSocket.getOutputStream();

String text = mEditText.getText().toString();

MultiFormatWriter multiFormatWriter = new MultiFormatWriter();

BitMatrix bitMatrix = multiFormatWriter.encode(text,BarcodeFormat.CODE_128,200,200);

BarcodeEncoder barcodeEncoder = new BarcodeEncoder();

Bitmap bitmap = barcodeEncoder.createBitmap(bitMatrix);

os.write("Hello".getBytes()); //Prints Hello 

如何使用相同的逻辑打印位图?

我尝试了一些类似的代码

int size = bitmap.getRowBytes() * bitmap.getHeight();

ByteBuffer byteBuffer = ByteBuffer.allocate(size);

bitmap.copyPixelsToBuffer(byteBuffer);

byte[] byteArray = byteBuffer.array();

os.write(byteArray);

但是这样可以使打印空白并保持滚动状态

我正在使用Godex-MX30打印机

1 个答案:

答案 0 :(得分:1)

您需要告诉打印机您要发送图像进行打印,并指定如何打印图像。

通常,这是通过ESC / POS代码完成的。像这样的大多数打印机都使用ESC / POS代码。

ESC *是这样指定的。您可以在这个问题java code或这个one's solution中查看许多示例。

有关更多信息,请参见Seiko Epson reference

不确定这台打印机,但是许多热敏票据打印机都支持使用Esc / Pos Code创建和打印条形码。您可以尝试使用this之类的东西。

相关问题