Decoding qr code from image stored on the phone with Zxing (on Android phone)

前端 未结 3 809
失恋的感觉
失恋的感觉 2020-12-05 06:20

I have an app that receives qr code from the server. I want to decode it (not with intent and camera) and display the text it contains in my app. I have alredy done this in

相关标签:
3条回答
  • 2020-12-05 06:23

    In android,you can do it this way:

        @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;
            }
        }
    
    0 讨论(0)
  • 2020-12-05 06:34

    Quickmark and qr droid actually reads out what the code says, and you can decode barcodes saved on your phone. Hit the menu button when your load the image and select share, find decode qr droid or decode quickmark, and the'll do the magic. I prefer quickmark for reading codes, because it tells me what is typed in the code.

    0 讨论(0)
  • 2020-12-05 06:47

    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.

    0 讨论(0)
提交回复
热议问题