journeyapps / zxing-android-embedded

Barcode scanner library for Android, based on the ZXing decoder
https://journeyapps.com/
Apache License 2.0
5.68k stars 1.26k forks source link

otaliastudios.cameraview and zxing decode qrcode #655

Open openmotion opened 2 years ago

openmotion commented 2 years ago

Description of the problem:

Hello i have to decode qrcode using the otaliastudios.cameraview library there is a frameprocessor

i have this result

direct decode exception com.google.zxing.NotFoundException DecodeHintType.PURE_BARCODE exception com.google.zxing.NotFoundException

i try to decode directly the byte[] data

` if (frame.getDataClass() == byte[].class) { byte[] data = frame.getData();

                Decoder barcodeEncoder = new com.journeyapps.barcodescanner.Decoder();

                InputStream is = new ByteArrayInputStream(data);

//convert the image to a binary bitmap source LuminanceSource source = new BufferedImageLuminanceSource(is); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

//decode the barcode QRCodeReader reader = new QRCodeReader();

                // Process byte array...
                Log.d(TAG,"Process byte array...");
                int length_data = data.length;
                Log.d(TAG,"length_data : "+length_data);

                YuvImage yuvimage=new YuvImage(data, ImageFormat.NV21, 100, 100, null);
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                yuvimage.compressToJpeg(new Rect(0, 0, 100, 100), 80, baos);
                byte[] jdata = baos.toByteArray();

                Bitmap mBitmap = null;
                try {
                    mBitmap = BitmapFactory.decodeByteArray(jdata , 0, jdata.length);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if(mBitmap == null) {
                    Log.e(TAG,"mBitmap null ");
                }
                try {
                   mBitmap = convertBlackWhiteFull(mBitmap);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                int[] intArray = new int[0];
                try {
                    intArray = new int[mBitmap.getWidth()*mBitmap.getHeight()];
                } catch (Exception e) {
                    e.printStackTrace();
                }
                LuminanceSource source = null;
                try {
                    source = new RGBLuminanceSource(mBitmap.getWidth(), mBitmap.getHeight(), intArray);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                BinaryBitmap bitmap = null;
                try {
                    bitmap = new BinaryBitmap(new HybridBinarizer(source));
                } catch (Exception e) {
                    e.printStackTrace();
                }

                QRCodeReader reader_qr = new QRCodeReader();
                Result result_qr = null;
                try
                {
                    result_qr = reader_qr.decode(bitmap);
                    Log.d(TAG,"result_qr ok..."+result_qr);
                }
                catch (ReaderException e)
                {
                    Log.d(TAG,"ReaderException ok..."+e);
                }

                Log.d(TAG,"bitmap ok...");
                MultiFormatReader reader = new MultiFormatReader();
                try {
                    Log.d(TAG,"dcode ...");
                    Result result = reader.decode(bitmap);
                    Log.e(TAG, "result : "+result);
                } catch (NotFoundException e) {
                    Log.e(TAG, "direct decode exception", e);
                    Map<DecodeHintType,Object> tmpHintsMap = new EnumMap<DecodeHintType, Object>(DecodeHintType.class);
                    tmpHintsMap.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
                    tmpHintsMap.put(DecodeHintType.POSSIBLE_FORMATS, EnumSet.allOf(BarcodeFormat.class));
                    tmpHintsMap.put(DecodeHintType.PURE_BARCODE, Boolean.FALSE);
                    try {
                        Result result = reader.decode(bitmap, tmpHintsMap);
                        Log.e(TAG, "result : "+result);
                    } catch (NotFoundException ex) {
                        Log.e(TAG, "DecodeHintType.PURE_BARCODE exception", ex);

                    }
                }`

Which library version are you using? E.g. 3.2.0.

com.journeyapps:zxing-android-embedded:4.2.0

Which phone/tablet are you using, and which Android version does it run? (e.g. Samsung Galaxy S5, Android 5.0)

huawei mate xs

Does the same happen on other devices or an emulator?

Can you reproduce the issue in the sample project included with the library? If not, can you provide your own sample project or sample code that produces this error?

In the case of an error do you have a stack trace or adb logs?