Go directly to the Code. The Code has specific resolutions on it and provides jar for download: character code jarpack.rar
Generate the corresponding QR code based on the text:
// Generate the QR map private void createimage () {try {// you need to introduce the core package qrcodewriter writer = new qrcodewriter (); string text = qr_text.gettext (). tostring (); log. I (TAG, "generated text:" + text); If (text = NULL | "". equals (text) | text. length () <1) {return ;}// convert the input text into a two-dimensional code bitmatrix martix = writer. encode (text, barcodeformat. qr_code, qr_width, qr_height); system. out. println ("W:" + martix. getwidth () + "H:" + martix. getheight (); hashtable <encodehinttype, string> hints = new hashtable <encodehinttype, string> (); hints. put (encodehinttype. character_set, "UTF-8"); bitmatrix = new qrcodewriter (). encode (text, barcodeformat. qr_code, qr_width, qr_height, hints); int [] pixels = new int [qr_width * qr_height]; for (INT y = 0; y <qr_height; y ++) {for (INT x = 0; x <qr_width; X ++) {If (bitmatrix. get (x, y) {pixels [y * qr_width + x] = 0xff000000;} else {pixels [y * qr_width + x] = 0 xffffffff ;}}} bitmap bitmap = bitmap. createbitmap (qr_width, qr_height, bitmap. config. argb_8888); bitmap. setpixels (pixels, 0, qr_width, 0, 0, qr_width, qr_height); qr_image.setimagebitmap (Bitmap);} catch (writerexception e) {e. printstacktrace ();}}
Read content based on the QR code:
// Parse the QR image private void scanningimage () {Map <decodehinttype, string> hints = new hashmap <decodehinttype, string> (); hints. put (decodehinttype. character_set, "UTF-8"); // obtain the image to be parsed. Bitmap bitmap = (bitmapdrawable) qr_image.getdrawable ()). getbitmap (); rgbluminancesource source = new rgbluminancesource (Bitmap); binarybitmap bitmap1 = new binarybitmap (new region (source); qrcodereader reader = new qrcodereader (); result; try {result = reader. decode (bitmap1, hints); // obtain the parsed text qr_result.settext (result. gettext ();} catch (notfoundexception e) {e. printstacktrace ();} catch (checksumexception e) {e. printstacktrace ();} catch (formatexception e) {e. printstacktrace ();}}