在不使用相机的情况下解码QRcode图像

时间:2012-05-30 09:25:49

标签: android qr-code zxing

伙计我正在开发一款用于阅读二维码的Android应用程序。我实现了ZXing库,但我不能使用相机。我需要将QR码保存为图像,并使用与ZXing解码相关的功能将QR码存储为图像...任何想法?

我检查了论坛,但我需要更完整的东西...... :(

1 个答案:

答案 0 :(得分:5)

是的,您可以在不使用相机的情况下解码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;
}