Reputation: 629
I want to generate qr code of a text in my application i have to zxing library but I have no idea to implement this. how can I implement this?any help
Upvotes: 1
Views: 8278
Reputation: 12049
You need to add the core.jar
file from the latest release of ZXing to your project. You also need to add two more classes to your project.
Here is a step-by-step guide on how to do so.
Upvotes: 3
Reputation: 385
QRCodeWriter writer = new QRCodeWriter();
try
{
EnumMap<EncodeHintType, Object> hint = new EnumMap<EncodeHintType, Object>(EncodeHintType.class);
hint.put(EncodeHintType.CHARACTER_SET, "UTF-8");
BitMatrix bitMatrix = writer.encode(content, BarcodeFormat.QR_CODE, dimention, dimention, hint);
int width = bitMatrix.getWidth();
int height = bitMatrix.getHeight();
int[] pixels = new int[width * height];
for (int y = 0; y < height; y++)
{
int offset = y * width;
for (int x = 0; x < width; x++)
{
// pixels[offset + x] = bitMatrix.get(x, y) ? 0xFF000000
// : 0xFFFFFFFF;
pixels[offset + x] = bitMatrix.get(x, y) ? colorBack : colorFront;
}
}
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;
Upvotes: 3
Reputation: 2436
below code can help you to generate qr code
Intent intent = new Intent();
intent.setAction(Intents.Encode.ACTION);
intent.putExtra(Intents.Encode.FORMAT, BarcodeFormat.QR_CODE.toString());
intent.putExtra(Intents.Encode.TYPE, Contents.Type.TEXT);
intent.putExtra(Intents.Encode.DATA, codeString);
QRCodeEncoder qrcode = new QRCodeEncoder(YourActivity.this, intent,250);
try {
Bitmap bitmap = qrcode.encodeAsBitmap();
imgBarcode = (ImageView) findViewById(R.id.imgbarcode);
imgBarcode.setImageBitmap(bitmap);
} catch (WriterException e) {
e.printStackTrace();
}
Upvotes: 2