Public voidcreateqrimage (String url) {Try { //Determine URL legitimacy if(url = =NULL|| ". Equals (URL) | | Url.length () < 1) { return; } Hashtable<encodehinttype, string> hints =NewHashtable<encodehinttype, string>(); Hints.put (Encodehinttype.character_set,"Utf-8"); //conversion of image data using matrix conversionBitmatrix Bitmatrix =NewQrcodewriter (). Encode (URL, Barcodeformat.qr_code, qr_width, qr_height, hints); int[] pixels =New int[Qr_width *Qr_height]; //here according to the two-dimensional code algorithm, one by one to generate two-dimensional code of the picture,//Two for loop is the result of the picture Heng Lie scan for(inty = 0; Y < Qr_height; y++) { for(intx = 0; x < qr_width; X + +) { if(Bitmatrix.get (x, y)) {pixels[y* qr_width + x] = 0xff000000;//There is information to set the pixel color.}Else{pixels[y* qr_width + x] = 0x0000a0e9;//no information set pixel color } } } //Create a QR code image format, using argb_8888Bitmap Bitmap =Bitmap.createbitmap (Qr_width, Qr_height, Bitmap.Config.ARGB_8888); Bitmap.setpixels (Pixels,0, qr_width, 0, 0, Qr_width, qr_height); //display to a imageview aboveimage.setvisibility (view.visible); Image.setimagebitmap (bitmap); } Catch(writerexception e) {e.printstacktrace (); } }
zxing library files in file management
Android uses zxing to generate two-dimensional code