In this article i will share you the code snippet to generate the QR code from any Text. Before this i want to brief you about QR code.
QR Code:
QR code is the trademark for a type of matrix barcode first designed in 1994 for the automotive industry in Japan. A barcode is a machine-readable optical label that contains information about the item to which it is attached.
So lets Start with the Coding Part :
For use This Method Simply Call to generate QR code :
Bitmap bitmap ;
String qrcode;
ImageView imageView;
qrcode="orderID=11xxx11&Name=UserName";
try {
bitmap = TextToImageEncode(qrcode);
imageView.setImageBitmap(bitmap);
} catch (WriterException e) {
e.printStackTrace();
}
That's All you need to generate QR code.
QR Code:
QR code is the trademark for a type of matrix barcode first designed in 1994 for the automotive industry in Japan. A barcode is a machine-readable optical label that contains information about the item to which it is attached.
So lets Start with the Coding Part :
Bitmap TextToImageEncode(String Value) throws WriterException {
BitMatrix bitMatrix;
try {
bitMatrix = new MultiFormatWriter().encode(
Value,
BarcodeFormat.DATA_MATRIX.QR_CODE,
QRcodeWidth, QRcodeWidth, null
);
} catch (IllegalArgumentException Illegalargumentexception) {
return null;
}
int bitMatrixWidth = bitMatrix.getWidth();
int bitMatrixHeight = bitMatrix.getHeight();
int[] pixels = new int[bitMatrixWidth * bitMatrixHeight];
for (int y = 0; y < bitMatrixHeight; y++) {
int offset = y * bitMatrixWidth;
for (int x = 0; x < bitMatrixWidth; x++) {
pixels[offset + x] = bitMatrix.get(x, y) ?
getResources().getColor(R.color.blackcolor):getResources().getColor(R.color.white);
}
}
Bitmap bitmap = Bitmap.createBitmap(bitMatrixWidth, bitMatrixHeight, Bitmap.Config.ARGB_4444);
bitmap.setPixels(pixels, 0, 500, 0, 0, bitMatrixWidth, bitMatrixHeight);
return bitmap;
}
For use This Method Simply Call to generate QR code :
Bitmap bitmap ;
String qrcode;
ImageView imageView;
qrcode="orderID=11xxx11&Name=UserName";
try {
bitmap = TextToImageEncode(qrcode);
imageView.setImageBitmap(bitmap);
} catch (WriterException e) {
e.printStackTrace();
}
That's All you need to generate QR code.
Comments
Post a Comment