A function to generate two-dimensional code
public static Bitmap Createqrcode (String str) throws Writerexception {
Hashtable<encodehinttype, string> hints = new Hashtable<encodehinttype, string> ();
Hints.put (Encodehinttype.character_set, "utf-8");
Bitmatrix matrix = new Multiformatwriter (). Encode (str,
Barcodeformat.qr_code, 300, 300);
int width = matrix.getwidth ();
int height = matrix.getheight ();
int[] pixels = new int[width * height];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; + +) {
if (Matrix.get (x, y)) {
Pixels[y * width + x] = 0xff000000;
}else{
Pixels[y * width + x] = 0xFFFFFFFF; -1 equivalent to 0xFFFFFFFF White
}
}
}
Bitmap Bitmap = bitmap.createbitmap (width, height,
Bitmap.Config.RGB_565);
Bitmap.setpixels (pixels, 0, width, 0, 0, width, height);
return bitmap;
}
Android generates two-dimensional code