【发布时间】:2019-06-13 22:17:10
【问题描述】:
打印机不考虑图像的对齐方式。默认情况下,徽标始终左对齐。文本对齐没有问题。所以aligncenter()方法没有问题。当我在while循环内设置对齐时,一系列问号会打印在纸上。
public void printImage(Bitmap bitmap, boolean center) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int newWidth = this.mType58 ? 384 : 576;
if (width > (this.mType58 ? 384 : 576)) {
bitmap = LibUtil.setImgSize(bitmap, (float) newWidth, (float) (height / (width / newWidth)), (float) width, (float) height);
}
try {
PrinterWriter mThirdPrinter = this.mType58 ? new PrinterWriter58mm(384, 384) : new PrinterWriter80mm(576, 576);
ArrayList<byte[]> datas = mThirdPrinter.getImageByte(bitmap);
if (mThirdPrinter.getDataAndClose() == null) {
if (this.mCallback != null) {
this.mCallback.onError(ErrorCode.IMAGE_NOT_FONUD);
}
return;
}
try {
datas.add(mThirdPrinter.getDataAndClose());
} catch (NullPointerException e) {
e.printStackTrace();
}
if (datas == null) {
DebugLog.LogD("imgpath is empty, datas is null, maybe is TFCard");
return;
}
this.mPrinterModule.sendData(new byte[]{(byte) 27, (byte) 74, (byte) 0});
Iterator it = datas.iterator();
byte [] alignment = alignCenter();
int i = 0 ;
byte [] data1 = null ;
while (it.hasNext()) {
data1[i] = (byte) it.next();
}
this.mPrinterModule.sendData(alignment);
this.mPrinterModule.sendData(data1);
} catch (IOException e2) {
e2.printStackTrace();
}
}
【问题讨论】:
-
只需浏览存储库 -> github.com/imrankst1221/Thermal-Printer-in-Android 。它将回答您与热敏打印机相关的大部分问题。还有代码可以打印您正在寻找的中心对齐图像。
标签: android thermal-printer escpos