Harry
Harry

Reputation: 1

Printing out a bitmap QR code image with Brother Label Printer SDK prints out a blank label

I need to be able to print out a bitmap QR Code using my Brother QL-720NW.

As of right now, I'm able to generate a QR code bitmap and display it properly in an ImageView. On a button press, the user needs to be able to print that QR code bitmap from the Brother label printer.

I am able to make a connection to the printer, but I can only print out blank labels that do not show the QR code. How can I fix this so that the bitmap appears on the printed label properly?

Method for printing bitmap:

void printImage(Bitmap bitmap) {
    // Specify printer
    final Printer printer = new Printer();
    PrinterInfo settings = printer.getPrinterInfo();
    settings.ipAddress = "192.168.2.149";
    settings.workPath = "/storage/emulated/0/Download";

    settings.printerModel = PrinterInfo.Model.QL_720NW;
    settings.port = PrinterInfo.Port.NET;
    settings.orientation = PrinterInfo.Orientation.LANDSCAPE;
    //settings.paperSize = PrinterInfo.PaperSize.CUSTOM;
    settings.align = PrinterInfo.Align.CENTER;
    settings.valign = PrinterInfo.VAlign.MIDDLE;
    settings.printMode = PrinterInfo.PrintMode.ORIGINAL;
    settings.numberOfCopies = 1;
    settings.labelNameIndex = LabelInfo.QL700.W62RB.ordinal();
    settings.isAutoCut = true;
    settings.isCutAtEnd = false;

    printer.setPrinterInfo(settings);


    // Connect, then print
    new Thread(new Runnable() {
        @Override
        public void run() {
            if (printer.startCommunication()) {
                Log.e("Tag: ", "Connection made.");
                PrinterStatus result = printer.printImage(bitmap);
                Log.e("Tag: ", "Printing!");
                if (result.errorCode != PrinterInfo.ErrorCode.ERROR_NONE) {
                    Log.d("TAG", "ERROR - " + result.errorCode);
                }
                printer.endCommunication();
            }
            else {
                Log.e("Tag: ", "Cannot make a connection.");
            }
        }
    }).start();
}

Generating bitmap:

Bitmap encodeAsBitmap(String str) throws WriterException {

    QRCodeWriter writer = new QRCodeWriter();
    BitMatrix bitMatrix = writer.encode(str, BarcodeFormat.QR_CODE, 100, 100);

    int w = bitMatrix.getWidth();
    int h = bitMatrix.getHeight();
    int[] pixels = new int[w * h];

    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            pixels[y * w + x] = bitMatrix.get(x, y) ? Color.BLACK : Color.WHITE;
        }
    }

    Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, w, 0, 0, w, h);
    return bitmap;
}

Upvotes: 0

Views: 886

Answers (1)

Harry
Harry

Reputation: 1

Solved it, I was using LabelInfo.QL700.W62RB.ordinal() for the LabelNameIndex when I should have been using LabelInfo.QL700.W62.ordinal().

Works perfectly now!

Upvotes: 0

Related Questions