ZXing Result.getRawBytes(), what exactly is it?

喜欢而已 提交于 2019-12-08 00:19:54

问题


I'm working with the zxing QR code APIs, and I'm trying to extract binary data from a QR code on an android device. However, on android, Result.getResultMetadata() isn't passed through to me through the Intent, so I tried to use Result.getRawBytes() to retrieve my byte array. However, getRawBytes() does not seem to return the same thing.

What exactly is Result.getRawBytes() and does anyone know how to extract byte arrays from zxing QR codes properly?

Thanks


回答1:


So what i think you want is the raw, decoded data in a byte array. The intent source that zxing gives you is missing the metadata, but it's still being sent to the intent filter.

In parseActivityResult inside of IntentIntegrator.java, you can add:

byte[] dataBytes = intent.getByteArrayExtra("SCAN_RESULT_BYTE_SEGMENTS_0");
return new IntentResult(contents,
                        formatName,
                        rawBytes,
                        orientation,
                        errorCorrectionLevel,
                        dataBytes);

I modified the IntentResult class to be able to take this extra piece:

private final byte[] dataBytes;

IntentResult() {
    this(null, null, null, null, null, null);
}

IntentResult(String contents,
           String formatName,
           byte[] rawBytes,
           Integer orientation,
           String errorCorrectionLevel,
           byte[] dataBytes) {
    this.contents = contents;
    this.formatName = formatName;
    this.rawBytes = rawBytes;
    this.orientation = orientation;
    this.errorCorrectionLevel = errorCorrectionLevel;
    this.dataBytes = dataBytes;
}


/**
* @return raw content of barcode in bytes
*/

public byte [] getDataBytes() {
  return dataBytes;
}

This byte array stores the first array of the metadata, AKA the raw contents of your data in bytes.




回答2:


Why not start with the javadoc?

It is the raw codewords in the QR code. It is not the individual parsed byte segments.



来源:https://stackoverflow.com/questions/11368684/zxing-result-getrawbytes-what-exactly-is-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!