Android uses zxing to generate two-dimensional code

Source: Internet
Author: User

 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.