【问题标题】:Printing out a bitmap QR code image with Brother Label Printer SDK prints out a blank label使用 Brother Label Printer SDK 打印位图二维码图像打印出空白标签
【发布时间】:2022-08-02 22:14:39
【问题描述】:

我需要能够使用 Brother QL-720NW 打印位图 QR 码。

截至目前,我能够生成二维码位图并在 ImageView 中正确显示。按下按钮后,用户需要能够从 Brother 标签打印机打印该二维码位图。

我可以连接到打印机,但我只能打印出不显示二维码的空白标签。如何解决此问题,以便位图正确显示在打印的标签上?

打印位图的方法:

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();
}

生成位图:

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;
}

    标签: java android android-studio bitmap brother-print-sdk


    【解决方案1】:

    解决了,当我应该使用 LabelInfo.QL700.W62.ordinal() 时,我使用 LabelInfo.QL700.W62RB.ordinal() 作为 LabelNameIndex。

    现在完美运行!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-01
      • 1970-01-01
      相关资源
      最近更新 更多