Decoding a qr code from an image stored on a phone using Zxing (on an Android phone)

I have an application that receives qr code from a server. I want to decode it (not with intent and camera) and display the text contained in my application. I have alredy done this in Java SE with jars from zxing using this code:

private class QRCodeDecoder { public String decode(File imageFile) { BufferedImage image; try { image = ImageIO.read(imageFile); } catch (IOException e1) { return "io outch"; } // creating luminance source LuminanceSource lumSource = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(lumSource)); // barcode decoding QRCodeReader reader = new QRCodeReader(); Result result = null; try { result = reader.decode(bitmap); } catch (ReaderException e) { return "reader error"; } return result.getText(); } } 

But on Android BufferedImage not found. Has anyone decrypted the qr code on the android from the image stored on the phone? Tnx.

+4
source share
3 answers

In android you can do it like this:

  @Override protected Result doInBackground(Void... params) { try { InputStream inputStream = activity.getContentResolver().openInputStream(uri); Bitmap bitmap = BitmapFactory.decodeStream(inputStream); if (bitmap == null) { Log.e(TAG, "uri is not a bitmap," + uri.toString()); return null; } int width = bitmap.getWidth(), height = bitmap.getHeight(); int[] pixels = new int[width * height]; bitmap.getPixels(pixels, 0, width, 0, 0, width, height); bitmap.recycle(); bitmap = null; RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels); BinaryBitmap bBitmap = new BinaryBitmap(new HybridBinarizer(source)); MultiFormatReader reader = new MultiFormatReader(); try { Result result = reader.decode(bBitmap); return result; } catch (NotFoundException e) { Log.e(TAG, "decode exception", e); return null; } } catch (FileNotFoundException e) { Log.e(TAG, "can not open file" + uri.toString(), e); return null; } } 
+10
source

Download ZXing from google code, and this class file: ZXing-1.6/zxing-1.6/androidtest/src/com/google/zxing/client/androidtest/RGBLuminanceSource.java can help you.

+2
source

Quickmark and qr droid really read what the code says, and you can decode the barcodes stored on your phone. Press the menu button when you upload the image and select sharing, find the qr droid decoder or decrypt quickmark and you will do the magic. I prefer quickmark for reading codes, because it tells me what is typed in the code.

-3
source

All Articles