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