Program Resource

Resource libraries for programmers and developers

Reading structured array isn’t difficult; you can use Zxing library as is.

Below is part of source code from my Animal Crossing designer app.

private static final String ENCORD_NAME = "ISO-8859-1";

public byte[] decodeCameraBinQRCode(byte[] qrbmp,int width,int height) {
    PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(qrbmp,width,height,0,0,width,height,false);
    Hashtable decodeHint = new Hashtable();
    decodeHint.put(DecodeHintType.CHARACTER_SET, ENCORD_NAME);
    decodeHint.put(DecodeHintType.TRY_HARDER, true);
    BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));
    Reader reader = new QRCodeReader();
    Result result = reader.decode(binaryBitmap, decodeHint);
    public byte[] rawqrcode;

    byte[] dataByte = result.getText().getBytes(ENCORD_NAME);
    rawqrcode = result.getRawBytes();

    if ((rawqrcode[0] & 0xf0) == 0x30){
        int current = (rawqrcode[0] & 0x0f);
        code_total = ((rawqrcode[1] & 0xf0) >> 4) + 1;
        code_parity = ((rawqrcode[1] & 0x0f) << 4) | ((rawqrcode[2] & 0xf0) >> 4);
        ...
    }

Data is decoded to Binary (since QR data is binary in Animal Crossing), and decodeHint parameter is set that way.

For structured array QR code, total pages, current page, and other info is written in header part. To get header data,

rawqrcode = result.getRawBytes();

above getRawBytes() function is used. This function returns all raw QR code data including header data. For structured array QR code, leading 5 bytes has following data.

3N TP PE SS SS
  • 4bit on left side of 0 byte in QR code header is 3
  • N is current number of QR code (0 start)
  • T is total number of QR codes (since 4bit, max QR array is 16)
  • PP is parity
  • E is encoding type, 4 for binary
  • SS for QR code data size

Parity is 8bit, 0 – 255, and this is used for ID for structured array QR code. This is used to determine QR code is part of same group; all QR codes in group contains same parity. When reading structured array QR code in sequence, you should check position of QR (N), total pages of QR (T), and parity (PP).

This data is “current”, “code_total”, “code_parity” in above sample code. Simply repeat reading QR code until all required codes are read, and once all data is read, merge data and move to next step.

Print Friendly, PDF & Email

This post is also available in: Japanese

Read/Write multi QR code using Zxing Part2 : Reading QR」 に3件のコメント

  1. Fleta says:

    That’s not even 10 mituens well spent!

  2. Shrikant Yadav says:

    Can you please tell how we can create structured append QR code for an binary value which is having length about 5000?

  3. Thao says:

    In Andoird, the camera has already supported to return byte[] data from QRCode, but in iOS, please tell me how to use this function above. I don’t know how to get the byte[] of the QRCode. Thank you

Leave a Reply to Shrikant Yadav Cancel reply

Your email address will not be published. Required fields are marked *


*

CAPTCHA