伙计们,我正在开发一个用于读取 QR 码的 Android 应用程序。我实现了库 ZXing,但我不能使用相机。我需要获取保存为图像的二维码并使用与 ZXing 解码存储为图像的二维码相关的功能......有什么想法吗?
我检查了论坛,但我需要更完整的东西..:(
是的,您可以在不使用相机的情况下解码 QR。您必须从图库中导入图像,获取位图并将其传递给LuminanceSource source = new RGBLuminanceSource(bMap);
这里是代码。
LuminanceSource source = new RGBLuminanceSource(bMap);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Reader reader = new MultiFormatReader();
try {
Result result = reader.decode(bitmap);
String contents = result.getText();
byte[] rawBytes = result.getRawBytes();
BarcodeFormat format = result.getBarcodeFormat();
ResultPoint[] points = result.getResultPoints();
} catch (NotFoundException e) {
e.printStackTrace();
return;
} catch (ChecksumException e) {
e.printStackTrace();
return;
} catch (FormatException e) {
e.printStackTrace();
return;
}