zxing-android-embedded icon indicating copy to clipboard operation
zxing-android-embedded copied to clipboard

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

Open sylvesterroos opened this issue 3 years ago • 1 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')

sylvesterroos avatar Aug 07 '22 11:08 sylvesterroos

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

khavnu avatar Sep 12 '22 07:09 khavnu