ZXing Result.getRawBytes(),它到底是什么



我正在使用 zxing 二维码 API,我正在尝试从安卓设备上的二维码中提取二进制数据。但是,在Android上,Result.getResultMetadata()没有通过Intent传递给我,所以我尝试使用Result.getRawBytes()来检索我的字节数组。但是,getRawBytes() 似乎没有返回相同的内容。

Result.getRawBytes() 到底是什么,有谁知道如何正确地从 zxing QR 码中提取字节数组?

谢谢

所以我认为你想要的是字节数组中的原始解码数据。zxing 为您提供的意图源缺少元数据,但仍被发送到意图过滤器。

在 IntentIntegrator.java 的 parseActivityResult 中,您可以添加:

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

我修改了IntentResult类,以便能够获得这个额外的部分:

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;
}
此字节数组

存储元数据的第一个数组,即数据的原始内容(以字节为单位)。

为什么不从javadoc开始呢?

它是二维码中的原始码字。它不是单个解析的字节段。

最新更新