Android扫码方案

本文探讨了Android平台的两种扫码方案,Google的MLKIT因其机器学习基础提供了两种集成方式,但可能面临应用大小和地域限制;而zxing的zxing-android-embedded则更为传统,适合主动获取预览图的需求。

Android扫码方案

概述
两套方案,Google的ML KIT套件,zxing的zxing-android-embedded

选型第二种,优缺点自己评估 理论上google的套件更优雅可靠但是其基于机器学习仅提供两种方式,捆绑训练模型包或Google Play服务,让应用变得更大或国内无法使用Google服务

初始方案看示例即可

private final ActivityResultLauncher<ScanOptions> barcodeLauncher = registerForActivityResult(new ScanContract(),
            result -> {
				// 处理单独扫码时的扫码结果 result.getContents()
			}
 });

ScanOptions options = new ScanOptions();
options.setDesiredBarcodeFormats(ScanOptions.ONE_D_CODE_TYPES);
options.setPrompt("扫描条码");
options.setCameraId(0);  // Use a specific camera of the device
options.setBeepEnabled(false);
options.setBarcodeImageEnabled(true);
options.setCaptureActivity(ContinuousCaptureActivity.class);
viewBinding.videoCaptureButton.setOnClickListener(i -> barcodeLauncher.launch(options));

扫码时主动获取预览图方案

ISSUE
需求描述:扫码与拍摄分离,在点击按钮时获取预览图图像

barcodeView.getBarcodeView().setUseTextureView(true);
Bitmap bitmap = ((TextureView) barcodeView.getBarcodeView().getChildAt(0)).getBitmap();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值