如何从预览android解码QR码图像?

时间:2012-05-29 12:38:03

标签: android android-camera qr-code zxing

我初始化了相机并开始进入预览模式。对于预览,我从http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/CameraPreview.html

获取源代码

现在我想从预览中用zxing库解码QR码,但我不知道如何做.. 你能打发我吗?

1 个答案:

答案 0 :(得分:1)

如果你想用zwing解码QR码,你需要使用这两个类:

IntentIntegrator.java
IntentResult.java

在您的活动中调用这样的意图:

IntentIntegrator intentScan = new IntentIntegrator(this);
Collection<String> desiredBarcodeFormat = Collections.unmodifiableCollection(Arrays.asList("QR_CODE"));
intentScan.initiateScan();

您使用此方法在活动中收到结果:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case IntentIntegrator.REQUEST_CODE:
        if (resultCode == RESULT_OK) {
            IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
            if (scanResult != null)
               String out = scanResult.getContents();
        }
    }
}

文档链接:

http://code.google.com/p/zxing/wiki/ScanningViaIntent

链接到课程:

http://code.google.com/p/zxing/source/browse/trunk/android-integration/src/com/google/zxing/integration/android/