gpt4 book ai didi

java - 修复 Zxing (Obj-C) 中的 Aztec 解码器以返回原始 ByteArray

转载 作者:太空宇宙 更新时间:2023-11-04 13:04:49 24 4
gpt4 key购买 nike

我正在开发一个 iOS 应用程序,该应用程序应该解码某种类型的 Aztec 条形码( example ,PDF)。我需要扫描仪返回较低级别的数据,因为它是 zlib 压缩的,之后我需要将其解压缩。使用 AVCapture 的内置条形码扫描仪对于常规字符串数据工作得很好,但是 fails in my case .

我转向了 Zxing,或者更确切地说是它的 Objective C 端口 ZXingObjC ,希望能够在解码后的条形码数据变成字符串之前访问它。我就成功了一半。返回的 ZXResult 确实包含一个名为 rawBytesZXByteArray,但适用于 QR 码(对于 Aztec 码,它是 nil)!我往里面看ZXAztecDecoder.m果然,字节数组从未被填充,即使在 Java 的原始 Zxing 代码中也是如此。有人试图通过执行以下操作来修复原始库( Pull Request ,第 80 行)

byte[] rawBytes = convertBoolArrayToByteArray(correctedBits);

我想为 ZXingObjC 添加相同的功能,但我一直在尝试将 ZXBoolArray 转换为 ZXByteArray。这是我设想的解码函数:

- (ZXDecoderResult *)decode:(ZXAztecDetectorResult *)detectorResult error:(NSError **)error {
self.ddata = detectorResult;
ZXBitMatrix *matrix = [detectorResult bits];
ZXBoolArray *rawbits = [self extractBits:matrix];
if (!rawbits) {
if (error) *error = ZXFormatErrorInstance();
return nil;
}

ZXBoolArray *correctedBits = [self correctBits:rawbits error:error];
if (!correctedBits) {
return nil;
}

ZXByteArray *rawBytes = /* somehow turn correctedBits into ZXByteArray */;

NSString *result = [[self class] encodedData:correctedBits];
return [[ZXDecoderResult alloc] initWithRawBytes:rawBytes text:result byteSegments:nil ecLevel:nil];
}

如果有人知道如何做到这一点或知道如何去做,我将不胜感激。如果成功的话,我想将代码贡献给 ZXingObjC,这样以后就不会困扰人们了。提前致谢!

最佳答案

这实际上并不是问题的解决方案,但我坚持不懈的唠叨帮助解决了this overdue issue在原始 ZXing Github 存储库中。如果该更改在某个时候使其上游到 ZXingObjC 中,我可以永远结束这个问题。

如果有人愿意帮助将这些 Java 行 ( source ) 翻译为 Objective-C,我一定会很感激。

/**
* Reads a code of length 8 in an array of bits, padding with zeros
*/
private static byte readByte(boolean[] rawbits, int startIndex) {
int n = rawbits.length - startIndex;
if (n >= 8) {
return (byte) readCode(rawbits, startIndex, 8);
}
return (byte) (readCode(rawbits, startIndex, n) << (8 - n));
}

/**
* Packs a bit array into bytes, most significant bit first
*/
static byte[] convertBoolArrayToByteArray(boolean[] boolArr) {
byte[] byteArr = new byte[(boolArr.length + 7) / 8];
for (int i = 0; i < byteArr.length; i++) {
byteArr[i] = readByte(boolArr, 8 * i);
}
return byteArr;
}

关于java - 修复 Zxing (Obj-C) 中的 Aztec 解码器以返回原始 ByteArray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34591448/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com