Gaurang Devmurari
Gaurang Devmurari

Reputation: 41

zxing library not scanning QR code black background and white code(Negative scan) in android

In My application using zxing library for scanning QR code but library can't support scanning white in black code(Negative scan) so please suggest me solution how can i resolve this issue.

Upvotes: 4

Views: 1531

Answers (2)

Baharvand
Baharvand

Reputation: 1

if you add zxing-android-embedded library, you must add this code to your launcher:

scannerLauncher1.launch(
ScanOptions().setPrompt("scan your code")
 .setDesiredBarcodeFormats(ScanOptions.ALL_CODE_TYPES)
 .addExtra(Intents.Scan.SCAN_TYPE, Intents.Scan.INVERTED_SCAN)
)

this code inverts your barcode color and can detect it! Goodluck

Upvotes: 0

Rohan Zemse
Rohan Zemse

Reputation: 49

Add below code, source.invert() will do your work

 LuminanceSource source = new RGBLuminanceSource(bitmaps[0].getWidth(), 
 bitmaps[0].getHeight(), intArray);
 BinaryBitmap bMap = new BinaryBitmap(new HybridBinarizer(source));

        try {
            result = reader.decode(bMap);
        } catch (Exception e) {
            BinaryBitmap bMap1 = new BinaryBitmap(new HybridBinarizer(source.invert()));
            try {
                result = reader.decode(bMap1);
            } catch (NotFoundException notFoundException) {
              //  notFoundException.printStackTrace();
            } catch (ChecksumException checksumException) {
                //checksumException.printStackTrace();
            } catch (FormatException formatException) {
                //formatException.printStackTrace();
            }
        }
        return result;

Upvotes: 0

Related Questions