I was having some problem when trying to generate QR code in Android Programming. Here is the Tutorial I followed. When my generate button on click, I am calling this method
public static int white = 0xFFFFFFFF;
public static int black = 0xFF000000;
public final static int WIDTH = 500;
try
{
Bitmap bmp = encodeAsBitmap("Life is a bitch");
imgView.setImageBitmap(bmp);
} catch (Exception e) {
e.printStackTrace();
}
Bitmap encodeAsBitmap(String str) throws WriterException {
BitMatrix result;
Bitmap bitmap=null;
try
{
result = new MultiFormatWriter().encode(str,
BarcodeFormat.QR_CODE, WIDTH, WIDTH, null);
int w = result.getWidth();
int h = result.getHeight();
int[] pixels = new int[w * h];
for (int y = 0; y < h; y++) {
int offset = y * w;
for (int x = 0; x < w; x++) {
pixels[offset + x] = result.get(x, y) ? black:white;
}
}
bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, WIDTH, 0, 0, w, h);
} catch (Exception iae) {
iae.printStackTrace();
return null;
}
return bitmap;
}