我目前正在尝试在支持bt的斑马打印机上打印保存在我的Android设备上的图像,我已经按照文档中的示例进行了操作,但我不能为我的生活弄清楚为什么它不打印。 BT图标在打印机上闪烁了一段时间,所以我知道正在建立连接,但没有任何反应。当我调用printImage()函数时,我给它图像的位置和所需的宽度和高度。我知道该文件存在,因为我可以看到它显示在imageview中。这是我的代码:
private void printImageTest() {
new Thread(new Runnable() {
@Override
public void run() {
try {
Looper.prepare();
Connection connection = new BluetoothConnection("AC:3F:A4:13:C2:24");
connection.open();
ZebraPrinter printer = ZebraPrinterFactory.getInstance(connection);
printer.printImage(signatureFile, 100, 100);
Thread.sleep(2000);
connection.close();
Looper.myLooper().quit();
} catch (ConnectionException e) {
e.printStackTrace();
} catch (ZebraPrinterLanguageUnknownException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
答案 0 :(得分:1)
请在Image Load
连接到打印机:
BluetoothConnection printerConnection = new BluetoothConnection(printerAddress);
printerConnection.open();
if (!printerConnection.isConnected()) {
throw new Exception("Could not open bluetooth connection");
}
//print
ZebraPrinter printer = ZebraPrinterFactory.getInstance(printerConnection);
PrinterLanguage pl = printer.getPrinterControlLanguage();
if (pl == PrinterLanguage.CPCL) {
} else {
//byte[] configLabel = createZplReceipt().getBytes();
byte[] configLabel = zplContent.getBytes();
printerConnection.write(configLabel);
}
printerConnection.close();
然后将ZPL字符串发送到打印机: