如何将QRCode图像打印到蓝牙打印Android?

时间:2018-08-31 14:46:51

标签: android arrays printing bluetooth byte

大家好,我在这里关注这个问题

link to tutorial in stackoverflow

我正在使用这个库

library thermal print

但是当我打印时,这总是我拥有的图像:

print image

这是我的代码

byte[] printformat = { 0x1B, 0*21, FONT_TYPE };
            //byte[] printformat = PrinterCommands.SELECT_BIT_IMAGE_MODE;
            mmOutputStream.write(printformat);

            String text="12330120130239331823";
            MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
            try {
                BitMatrix bitMatrix = multiFormatWriter.encode(text, BarcodeFormat.QR_CODE,400,250);
                BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
                Bitmap bitmap = barcodeEncoder.createBitmap(bitMatrix);
                printPhoto(bitmap);
            } catch (WriterException e) {
                e.printStackTrace();
            }

这是库中的代码

 //print photo
    public void printPhoto(Bitmap bmp) {
        try {

            if(bmp!=null){
                byte[] command = PrinterUtil.decodeBitmap(bmp);
                mmOutputStream.write(PrinterCommands.ESC_ALIGN_CENTER);
                printText(command);
            }else{
                Log.e("Print Photo error", "the file isn't exists");
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.e("PrintTools", "the file isn't exists");
        }
    }

我将打印格式更改为此

 public static byte[] SELECT_BIT_IMAGE_MODE = {0x1B, 0x2A, 33, 255, 3};

但是还是同样的问题。

有人可以帮忙吗?

0 个答案:

没有答案