Android uses Qrcode_swetake.jar to generate two-dimensional code

Source: Internet
Author: User

Only code that generates the QR code

The advantage is that the number of occupancy methods is less than 65535

public class Qrcodeutil {static Paint paint;static {paint = new Paint ();//Set a brush size of 3 yellow brush Paint.setcolor (color.black);p Aint.setstrokejoin (Paint.Join.ROUND);p aint.setstrokecap (Paint.Cap.ROUND);p aint.setstrokewidth (3);}  private static final int pic_size = 300;private static final int rect_size = 6;/** * Generate two-dimensional code (QRCODE) Picture * * @param content * @param */public Bitmap Encoderqrcode (String content) {Canvas G;try {qrcode Qrcodehandler = new QRCode (); qrcodehandler.se Tqrcodeerrorcorrect (' M '); Qrcodehandler.setqrcodeencodemode (' B '); qrcodehandler.setqrcodeversion (8); byte[] Contentbytes = Content.getbytes ("Utf-8"); Bitmap Bufferbitmap = Bitmap.createbitmap (Pic_size, Pic_size, Bitmap.Config.ARGB_8888); g = new Canvas (BUFFERBITMAP); G.drawcolor (Color.White)///Set offset not set may cause parsing error int pixoff = 2;//output content > QR code if (contentbytes.length > 0 && cont Entbytes.length <) {boolean[][] codeout = Qrcodehandler.calqrcode (contentbytes); for (int i = 0; i < Codeout.len Gth i++) {for (int j = 0; J &LT Codeout.length; J + +) {if (Codeout[j][i]) {Float left = J * rect_size + pixoff;float top = i * rect_size + pixoff;float right = (j + 1) * R Ect_size + pixoff;float Bottom = (i + 1) * rect_size + pixoff;g.drawrect (left, top, right, bottom, paint);}}} else {log.e ("Qrcodeencoderhandler", "qrcode content bytes Length =" + contentbytes.length+ "not in [0,120].");} return bufferbitmap;} catch (Exception e) {e.printstacktrace (); return null;}}}

  

Android uses Qrcode_swetake.jar 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.