最后,我找到了解决方案。代码是(源自此处):
import com.google.zxing.*;public static String scanQRImage(Bitmap bMap) { String contents = null; int[] intArray = new int[bMap.getWidth()*bMap.getHeight()]; //copy pixel data from the Bitmap into the 'intArray' array bMap.getPixels(intArray, 0, bMap.getWidth(), 0, 0, bMap.getWidth(), bMap.getHeight()); LuminanceSource source = new RGBLuminanceSource(bMap.getWidth(), bMap.getHeight(), intArray); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); Reader reader = new MultiFormatReader(); try { Result result = reader.depre(bitmap); contents = result.getText(); } catch (Exception e) { Log.e("QrTest", "Error decoding barpre", e); } return contents;}Gradle引用为:
dependencies { compile 'com.google.zxing:core:3.2.1'}用法:
InputStream is = new BufferedInputStream(new FileInputStream(file));Bitmap bitmap = BitmapFactory.depreStream(is);String depred=scanQRImage(bitmap);Log.i("QrTest", "Depred string="+depred);


