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

QR codes not getting recognized if it has a background #682

Closed nathanfallet closed 2 years ago

nathanfallet commented 2 years ago

Description of the problem:

My app is generating a QR code on a background. The code is well recognized by my iOS app, but on Android, only the code without background works.

Exemple : This one is not getting recognized: IMG_4728 While the raw code, is: IMG_4722

Which library version are you using? 4.3.0

Which phone/tablet are you using, and which Android version does it run? (e.g. Samsung Galaxy S5, Android 5.0) Tested on my Wiko running Android 5.0, on my girlfriend Xiaomi (don't know the Android version but it's something recent), and on the emulator (Pixel 3a) running Android API 31.

Does the same happen on other devices or an emulator? It happens on all the device I tested and mentioned above.

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? Yes, using the two images I uploaded above. One is getting recognized while the other not.

In the case of an error do you have a stack trace or adb logs? There is no error. Nothing happens while pointing the code on a background.

rkistner commented 2 years ago

The standard scan mode is for black / dark foreground on a white / light backround.

To handle a case like this, use the "Inverted" scan mode.

nathanfallet commented 2 years ago

@rkistner Is there a mode in which both can be recognized? Because both can be used by users. And I have my iOS app handling both of them too, so I would like my Android app to do the same.

rkistner commented 2 years ago

Yes, you can use the MIXED_SCAN mode:

https://github.com/journeyapps/zxing-android-embedded/blob/2324a5403e8b89b66631977b357d1b998f1caf7e/sample/src/main/java/example/zxing/MainActivity.java#L60

nathanfallet commented 2 years ago

Thanks!