//encoding method
Bitmap encodeAsBitmap(String str) throws WriterException {
int black = 0xFF000000;
int white = 0xFFFFFFFF;
int width=400;
int height=400;
BitMatrix result;
Bitmap bitmap=null;
try {
result = new MultiFormatWriter().encode(str,
BarcodeFormat.QR_CODE,height ,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);
//Use the same value of the height and width respectively
bitmap.setPixels(pixels, 0, 400, 0, 0, 400, 400);
} catch (Exception iae) {
iae.printStackTrace();
return null;
}
return bitmap;
}