I am creating an application that can scan a QR code and create a QR code. The scanning part is completed and is working properly. But when I try to create a QR code and show it in ImageView, the created QR code does not contain the correct text. I am using the ZXING library.
Hashtable<EncodeHintType, ErrorCorrectionLevel> hintMap = new Hashtable<>();
hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
QRCodeWriter qrCodeEncoder = new QRCodeWriter();
BitMatrix bitMatrix = qrCodeEncoder.encode(myText, BarcodeFormat.QR_CODE,
200, 200, hintMap);
height = bitMatrix.getHeight();
width = bitMatrix.getWidth();
final Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
for (x = 0; x < width; x++){
bmp.setPixel(x, y, bitMatrix.get(x,y) ? Color.BLACK : Color.WHITE);
}
ImageView myImage = (ImageView) findViewById(R.id.qr_code);
myImage.setImageBitmap(bmp);
source
share