ZXing Result.getRawBytes(),究竟是什么? [英] ZXing Result.getRawBytes(), what exactly is it?

查看:76
本文介绍了ZXing Result.getRawBytes(),究竟是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用zxing QR代码API,并且尝试从Android设备上的QR代码提取二进制数据.但是,在android上,Result.getResultMetadata()未通过Intent传递给我,因此我尝试使用Result.getRawBytes()检索我的字节数组.但是,getRawBytes()似乎不会返回相同的东西.

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.

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

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

谢谢

推荐答案

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

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.

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

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

我修改了IntentResult类,以便能够增加这部分内容:

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.

这篇关于ZXing Result.getRawBytes(),究竟是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆