Skip to content

Instantly share code, notes, and snippets.

@Iltwats
Last active March 31, 2022 06:37
Show Gist options
  • Save Iltwats/98dde00eb29dc04739e37fa64822369d to your computer and use it in GitHub Desktop.
Save Iltwats/98dde00eb29dc04739e37fa64822369d to your computer and use it in GitHub Desktop.
private void qrGeneration(String qrText) {
QRCodeWriter writer = new QRCodeWriter();
try {
BitMatrix bitMatrix = writer.encode(qrText, BarcodeFormat.QR_CODE, 564, 564);
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);
}
}
bitmap = bmp;
((ImageView) findViewById(R.id.qrImage)).setImageBitmap(bmp);
} catch (WriterException e) {
e.printStackTrace();
}
}
// Just set the bitmap to any imageView you want it to show.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment