ZXing:使用 UPC 扫描条形码 + 5 补充

发布于 2024-12-21 16:54:53 字数 901 浏览 1 评论 0原文

我正在尝试使用 ZXing 库扫描如下所示的条形码。 条形码图像
(来源:minus.com

// start scanning
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "ONE_D_MODE");
startActivityForResult(intent, REQUEST_CODE);

如果我替换“ONE_D_MODE”“TWO_D_MODE” 时,应用程序可以成功检测这两个条形码;但 result 的值不会改变(仍然是 051488005995)。

// onActivityResult
if(requestCode == REQUEST_CODE && resultCode == RESULT_OK)
    String result = intent.getStringExtra("SCAN_RESULT");

有没有办法同时获取条形码值 051488005995 和 50115?

任何其他获取条形码上方的 isbn (0142501158) 而不获取补充 +5 条形码 (50115) 的方法也很好。

谢谢。

I'm trying to scan barcode as shown below using the ZXing library.
Barcode Image
(source: minus.com)

// start scanning
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "ONE_D_MODE");
startActivityForResult(intent, REQUEST_CODE);

If I replace "ONE_D_MODE" with "TWO_D_MODE", the app can successfully detect both barcodes; but the value of result won't change (still 051488005995).

// onActivityResult
if(requestCode == REQUEST_CODE && resultCode == RESULT_OK)
    String result = intent.getStringExtra("SCAN_RESULT");

Is there any way to get both barcode value 051488005995 and 50115?

Any other way to obtain the isbn (0142501158) above the barcodes without getting the supplemental +5 barcode (50115) would also be great.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

鱼忆七猫命九 2024-12-28 16:54:53

ONE_D_MODE 适合您。您可能确实想要PRODUCT_MODE。不存在 TWO_D_MODE 这样的东西。通过设置它只会扫描所有默认格式。

它不扫描两个条形码。只需扫描产品代码即可。所以我不确定你所说的仅获取产品代码是什么意思:这就是你已经拥有的。我想你两者都想要。

MultipleBarcodeReader 不太适合这种情况,因为库的任何部分都不会自行扫描 UPC/EAN 补充。它仅作为 UPC 和 EAN 代码的扩展进行扫描。

它已经在 UPCEANExtensionSupport 中扫描某些类型的扩展条形码。它不会返回原始值,而是尝试解析元数据并将其返回到结果元数据中。如果这就是你真正想要的,它已经做到了。否则就必须修改代码。

如果它读取 UPC/EAN 代码但找不到扩展代码,则扫描不会失败,只会返回主代码。如果您希望它仅在找到两者时才返回,那么您必须再次更改核心库的副本。

ONE_D_MODE will work for you. You probably really want PRODUCT_MODE. There is no such thing as TWO_D_MODE. By setting this it just scans all default formats.

It is not scanning both barcodes. It is just scanning the product code. So I'm not sure what you mean about getting just the product code: that's what you already have. I assume you want both.

MultipleBarcodeReader is not quite for this situation as no part of the library scans for the UPC/EAN supplement by itself. It is scanned for as an extension to UPC and EAN codes only.

It will already scan for some types of extension barcode in UPCEANExtensionSupport. It doesn't give you back the raw values but rather tries to parse out metadata and returns that in result metadata. If that's what you really want, it already does this. Otherwise you have to modify the code.

If it reads the UPC/EAN code but can't find an extension code, it will not fail the scan, and will only return the primary code. If you want it to only return if both are found, again you'd have to change your copy of the core library.

风月客 2024-12-28 16:54:53

仅供参考,您可以通过 Intent/zxing 扫描 UPC 12+5 代码。唯一的问题是你必须强制+5,所以你无法扫描正常的条形码。

从我与@srowen的帖子中: https://github.com/zxing/zxing/ issues/217#issuecomment-54818496

将提示作为 Intent 的额外内容传递给 IntentIntegrator=>initiateScan (稍后我必须创建一个重写方法来使其成为可选):

// Force 5 digit extension
intentScan.putExtra("ALLOWED_EAN_EXTENSIONS", new int[] {5});

我确认它是从我的 Android logcat 中识别出来的:

DecodeHintManager﹕ Hints from the Intent: {ALLOWED_EAN_EXTENSIONS=[I@42a38540}

在我的扫描结果中检索到扩展值:

String extension = intent.getStringExtra("SCAN_RESULT_UPC_EAN_EXTENSION");

现在我得到了一些 UPC 12+5 :)

Content:079808007955, Format:UPC_A, Extension: 74700

FYI you can scan UPC 12+5 codes via Intent/zxing. The only catch is that you have to force the +5, so you can't scan normal barcodes.

From my thread with @srowen: https://github.com/zxing/zxing/issues/217#issuecomment-54818496

Passed the hint as an extra to the Intent, inside IntentIntegrator=>initiateScan (I'll have to make an overriden method to make this optional later):

// Force 5 digit extension
intentScan.putExtra("ALLOWED_EAN_EXTENSIONS", new int[] {5});

I confirmed it was recognized from my Android logcat:

DecodeHintManager﹕ Hints from the Intent: {ALLOWED_EAN_EXTENSIONS=[I@42a38540}

Retrieved extension values in my scan result:

String extension = intent.getStringExtra("SCAN_RESULT_UPC_EAN_EXTENSION");

Now I got some UPC 12+5 :)

Content:079808007955, Format:UPC_A, Extension: 74700
橙味迷妹 2024-12-28 16:54:53

据我所知,通过 Intent 使用 zxing 是不可能的。

但是,您可以直接将 ZXing 嵌入到代码中(通过将 ZXing 源添加到代码目录中)。然后您就可以使用com.google.zxing.MultipleBarcodeReader。函数 decodeMultiple() 返回一个条形码数组,然后可以对其进行进一步处理。


一个小例子:

// data: YUV camera preview; width/height: preview size
Result[] decode(byte[] data, int width, int height) {
    PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(data, width, height, 0, 0, width, height);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    MultipleBarcodeReader reader = new MultipleBarcodeReader(new MultiFormatOneDReader(null));
    return reader.decodeMultiple(bitmap);
}

As far as I know, this is not possible using zxing via an Intent.

However, you can embed ZXing in your code directly (by adding the ZXing source to your code directory). Then you are able to use the com.google.zxing.MultipleBarcodeReader. The function decodeMultiple() returns an array of barcodes which then can be processed further.


A small example:

// data: YUV camera preview; width/height: preview size
Result[] decode(byte[] data, int width, int height) {
    PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(data, width, height, 0, 0, width, height);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    MultipleBarcodeReader reader = new MultipleBarcodeReader(new MultiFormatOneDReader(null));
    return reader.decodeMultiple(bitmap);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文