安卓应用中的QR码扫描器

3
我想在我的应用程序中扫描二维码。我不想使用ZXing,因为如果用户没有此应用程序安装在设备上,它会引用Google Play。我还发现了这个:https://github.com/Gnzlt/AndroidVisionQRReader ,但我无法将其安装到Android Studio中,作者提出的所有3种方法都失败了。也许您知道其他方法(可能只需将依赖项放入gradle中)?

为什么它失败了?也许你做错了什么? - Christopher
3个回答

3

你从未说过你不知道如何处理安卓相机。你想使用zxing而不下载zxing应用程序,这就是我的代码片段所做的。 - Christoph Pacher

1

由于此库使用了Android Vision技术,为什么不试着使用android-vision项目作为样本来实现自己的代码呢?这样你就能获得更多的控制和灵活性,而且样本非常易于理解,直接来自谷歌。

您可以在此处找到概述

和在github上找到示例项目此处

我尝试运行了条形码阅读器示例,它完美地工作(对于QR码和条形码也是如此),MainActivity和BarcodeCaptureActivity是您需要编辑以进行自定义实现的主要内容。


-1

只需添加

compile 'com.google.zxing:core:3.2.1'

将zxing Java接口添加到您的应用程序build.gradle文件的依赖项部分,您就可以使用它,无需安装zxing应用程序。
MultiFormatReader mReader = new MultiFormatReader();
Map<DecodeHintType,Object> hints = new EnumMap<DecodeHintType,Object>(DecodeHintType.class);
hints.put(DecodeHintType.TRY_HARDER, true);
// select your barcode formats here
List<BarcodeFormat> formats = Arrays.asList(BarcodeFormat.QR_CODE);
hints.put(DecodeHintType.POSSIBLE_FORMATS, formats);

mReader.setHints(hints);

// your camera image here
Bitmap input;
int width = input.getWidth(), height = input.getHeight();
int[] pixels = new int[width * height];
input.getPixels(pixels, 0, width, 0, 0, width, height);
input.recycle();
input = null;
BinaryBitmap bb = new BinaryBitmap(new HybridBinarizer(new RGBLuminanceSource(width, height, pixels)));
Result result = mReader.decodeWithState(bb);
String resultString = result.getText();

位图输入我需要初始化。我需要放什么? - user5083158
@ninja_2012 相机图像... - Christoph Pacher

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接