From 35f88ca386d469183f525167290dbd778eef6564 Mon Sep 17 00:00:00 2001 From: herodotos Date: Wed, 7 May 2025 08:19:13 +0200 Subject: [PATCH] Fix for coloured QR code fails to scan #2366 --- app/src/main/java/protect/card_locker/Utils.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/protect/card_locker/Utils.java b/app/src/main/java/protect/card_locker/Utils.java index 3be629d71..787e73806 100644 --- a/app/src/main/java/protect/card_locker/Utils.java +++ b/app/src/main/java/protect/card_locker/Utils.java @@ -53,10 +53,11 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.zxing.BinaryBitmap; import com.google.zxing.LuminanceSource; import com.google.zxing.MultiFormatReader; +import com.google.zxing.DecodeHintType; import com.google.zxing.NotFoundException; import com.google.zxing.RGBLuminanceSource; import com.google.zxing.Result; -import com.google.zxing.common.HybridBinarizer; +import com.google.zxing.common.GlobalHistogramBinarizer; import com.google.zxing.multi.GenericMultipleBarcodeReader; import com.google.zxing.multi.MultipleBarcodeReader; @@ -82,6 +83,7 @@ import java.util.Calendar; import java.util.Collections; import java.util.Currency; import java.util.Date; +import java.util.EnumMap; import java.util.GregorianCalendar; import java.util.HashMap; import java.util.List; @@ -381,14 +383,17 @@ public class Utils { // ...and then turned into a binary bitmap from its luminance LuminanceSource source = new RGBLuminanceSource(bitmap.getWidth(), bitmap.getHeight(), intArray); - BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source)); + BinaryBitmap binaryBitmap = new BinaryBitmap(new GlobalHistogramBinarizer(source)); List parseResultList = new ArrayList<>(); try { MultiFormatReader multiFormatReader = new MultiFormatReader(); MultipleBarcodeReader multipleBarcodeReader = new GenericMultipleBarcodeReader(multiFormatReader); - Result[] barcodeResults = multipleBarcodeReader.decodeMultiple(binaryBitmap); + Map hints = new EnumMap<>(DecodeHintType.class); + hints.put(DecodeHintType.ALSO_INVERTED, Boolean.TRUE); + + Result[] barcodeResults = multipleBarcodeReader.decodeMultiple(binaryBitmap,hints); for (Result barcodeResult : barcodeResults) { Log.i(TAG, "Read barcode id: " + barcodeResult.getText());