Search code examples
javaqr-codebarcodezxing

remove margin/border space and set ErrorCorrectionLevel to 'H' on QR Codes generated by ZXing?


I want to generate QR Code with no margin/border space and ErrorCreationLevel.H using ZXing as you can see below:

Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
hints.put(com.google.zxing.EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
hints.put(com.google.zxing.EncodeHintType.MARGIN, 0);

QRCodeWriter writer = new QRCodeWriter();

writer.encode("rasool", BarcodeFormat.QR_CODE, 200, 200, hints);

By this way, the generated QR Code contains default margin/border space and can be scanned easily, but i expected that it shouldn't have any margin/border space.

And when i comment the line related to ErrorCreationLevel, then generated QR Code haven't any margin/border space, but cannot be scanned with smart phones and scanner softwares.

I'm using version 3.4.0 of ZXing.

how can i solve this problem?


Solution

  • Your difficulty with scanning will undoubtedly be related to fact that the reference decode algorithm requires that the quiet zone ("margin") remain intact, therefore the scanner is failing to detect, frame and binarize the symbol.

    The error correction level helps to recover missing/damaged information from a binarized symbol, but you are likely not even getting this far in the decode process without the quiet zone.