I'm using Journeyapp's ZXing Android Embedded library for my android app and I can generate a simple QR code using the following piece of code
private void init() {
ImageView qrImageView = (ImageView) findViewById(R.id.qr_image_view);
qrImageView.setImageBitmap(generateQRBitMap("a"));
}
private Bitmap generateQRBitMap(final String content) {
Map<EncodeHintType, ErrorCorrectionLevel> hints = new HashMap<>();
hints.put(EncodeHintType.ERROR_CORRECTION,ErrorCorrectionLevel.H);
QRCodeWriter qrCodeWriter = new QRCodeWriter();
try {
BitMatrix bitMatrix = qrCodeWriter.encode(content, BarcodeFormat.QR_CODE, 512, 512, hints);
int width = bitMatrix.getWidth();
int height = bitMatrix.getHeight();
Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
bmp.setPixel(x , y, bitMatrix.get(x,y) ? Color.BLACK : Color.WHITE);
}
}
return bmp;
} catch (WriterException e) {
e.printStackTrace();
}
return null;
}
However, I want to be able to generate something as cool as the one given below
Now I know that I may have to write a custom encoder for that, but I really don't know where to begin. The BitMatrix
class always creates a square QR code, but is there anything that I can use to create the odd shapes?
On click of button_scan_qr_code , CaptureActivity will start scanning using default camera. Once it scans any QR code, it sends back the result to onActivityResult the MainActivity . ZXing also provides online QR Code Generator. Enter the required fields, generate and scan it to get the results.
I found this library QRGen using ZXing and very easy to use. Whatever, to design at your desire, you may add another image behind of this QR code's Image View.
Sample Code for Generating QR Code
Bitmap myBitmap = QRCode.from("www.example.org").bitmap();
ImageView myImage = (ImageView) findViewById(R.id.imageView);
myImage.setImageBitmap(myBitmap);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With