journeyapps / zxing-android-embedded

Barcode scanner library for Android, based on the ZXing decoder
https://journeyapps.com/
Apache License 2.0
5.74k stars 1.27k forks source link

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

Closed sylvesterroos closed 1 year ago

sylvesterroos commented 2 years ago

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')

khavnu commented 2 years ago

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); `