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.

  • 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.

This post is also available in: Japanese

Leave a Reply

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