I am able to decode the QR code if its big in size and get the complete XML data. However the QR codes which are small in size are not getting decoded as QR codes. They are getting decoded as BarcodeFormat.UPC_E, which is a one dimensional bar code unlike QR code which is two dimensional. So the output for small QR codes is coming something like this 04400621, instead of the expected XML output. This is happening with the online tool https://zxing.org/w/decode.jspx as well.
Some small QR codes are getting decoded by the online tool if we crop just the QR code part of the aadhar but the API fails to decode if we pass the cropped part of the small images.
I am using below API present in com.google.zxing.MultiFormatReader class
Result decode(BinaryBitmap image, Map hints)
Putting breakpoints in MultiFormatReader library, I could see that QRCodeReader is not able to decode the QR code, however MultiFormatOneDReader is able to decode the same.
Hence the small QR codes are getting decoded as BarcodeFormat.UPC_E it seems.
Pasting the code snippet below:
String filePath = "xyz";
File file = new File(filePath);
FileInputStream fileInputStream = new FileInputStream(filePath);
BufferedImage bufferedImage = ImageIO.read(fileInputStream);
LuminanceSource bufferedImageLuminanceSource = new BufferedImageLuminanceSource(bufferedImage);
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(bufferedImageLuminanceSource));
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.CHARACTER_SET, "ISO-8859-1");
tmpHintsMap.put(DecodeHintType.PURE_BARCODE, Boolean.FALSE);(tried with and without this option)
Result result = new MultiFormatReader().decode(binaryBitmap, tmpHintsMap);