journeyapps / zxing-android-embedded

Barcode scanner library for Android, based on the ZXing decoder

Home Page:https://journeyapps.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How do I specify the level of error correction for the encoded text?

ex-nix opened this issue · comments

Description of the problem:

When I generate a QR code I want it to have 15% error correction. How do I specify this? I've looked through the README but there is no explanation.

My current code:

// initialize bit matrix
BitMatrix matrix = writer.encode(epc, BarcodeFormat.QR_CODE, 350, 350);
// initialize barcode encoder
BarcodeEncoder encoder = new BarcodeEncoder();
// initialize bitmap
Bitmap bitmap = encoder.createBitmap(matrix);
// set bitmap on image view
ivOutput.setImageBitmap(bitmap);

How would I go about specifying the error correction level?

Which library version are you using? E.g. 3.2.0.

4.3.0 (implementation 'com.journeyapps:zxing-android-embedded:4.3.0')

I hope this help you !

`
ErrorCorrectionLevel mErrorCorrectionLevel = ErrorCorrectionLevel.M;

Map<EncodeHintType, Object> hintsMap = new HashMap<>();
hintsMap.put(EncodeHintType.CHARACTER_SET, "utf-8");
if(isAztec or isPDF417){
hintsMap.put(EncodeHintType.ERROR_CORRECTION, mErrorCorrectionLevel.getBits());
} else {
hintsMap.put(EncodeHintType.ERROR_CORRECTION, mErrorCorrectionLevel);
}
BitMatrix bitMatrix = new MultiFormatWriter().encode(mContent, barcodeFormat, mWidth, mHeight, hintsMap);
`