【问题标题】:Printing barcodes on a bluetooth thermal printer在蓝牙热敏打印机上打印条码
【发布时间】:2019-04-08 09:24:10
【问题描述】:

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

我正在使用 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 打印机

【问题讨论】:

  • 询问打印机制造商。
  • 供应商没有对 Android 应用程序的开发人员支持,此打印机也可以使用 Play 商店中的第 3 部分应用程序打印条形码:play.google.com/store/apps/…

标签: android bluetooth barcode thermal-printer


【解决方案1】:

您需要告诉打印机您正在发送要打印的图像并指定如何打印。

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

ESC * 是如何指定的。您可以查看此问题java code 或此one's solution 中的许多示例。

欲了解更多信息,请参阅精工爱普生reference

不确定这款打印机,但许多热敏收据打印机也支持使用 Esc/Pos 代码创建和打印条形码。你可以试试this

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-28
    • 2019-08-27
    • 2019-11-23
    • 2019-01-27
    • 2022-12-25
    • 2013-11-11
    • 2021-04-14
    • 1970-01-01
    相关资源
    最近更新 更多