Generate QR code and QR code generator

Source: Internet
Author: User

Generate QR code and QR code generator

1. Use the zxing provided by google to generate a QR code without a logo

Public static void main (String [] args) {try {// String contet = "http://izhongwei.github.io/blog/index.html"; // QR code generation path String path = "E :"; multiFormatWriter multiFormatWriter = new MultiFormatWriter (); Map hints = new HashMap (); hints. put (EncodeHintType. CHARACTER_SET, "UTF-8"); BitMatrix bitMatrix = multiFormatWriter. encode (contet, BarcodeFormat. QR_CODE, 400,400, hints); // generate the QR code size File = new file (path, "test.jpg"); // generate the image path and name ImageWrite after the QR code is generated. writeToFile (bitMatrix, "jpg", file); // you need the ImageWrite class to generate the image System. out. println ("the QR code has been generated");} catch (Exception e) {e. printStackTrace ();}}

After running the main method:

2. Use google's zxing to generate a QR code containing the logo

Introduction:

In the QEcodeUtil. java class:

Package com. able. barcode; import java. awt. basicStroke; import java. awt. graphics; import java. awt. graphics2D; import java. awt. image; import java. awt. shape; import java. awt. geom. roundRectangle2D; import java. awt. image. bufferedImage; import java. io. file; import java. io. outputStream; import java. util. hashtable; import java. util. random; import javax. imageio. imageIO; import com. google. zxing. barcodeFormat; import com. g Oogle. zxing. binaryBitmap; import com. google. zxing. decodeHintType; import com. google. zxing. encodeHintType; import com. google. zxing. multiFormatReader; import com. google. zxing. multiFormatWriter; import com. google. zxing. result; import com. google. zxing. common. bitMatrix; import com. google. zxing. common. hybridBinarizer; import com. google. zxing. qrcode. decoder. errorCorrectionLevel;/***** @ author Xia Zhongwei * QR code tool class */publ Ic class QRCodeUtil {private static final String CHARSET = "UTF-8"; private static final String FORMAT_NAME = "JPG"; // two-dimensional code size private static final int QRCODE_SIZE = 300; // logo width private static final int WIDTH = 80; // logo height private static final int HEIGHT = 80; private static BufferedImage createImage (String content, String imgPath, boolean needCompress) throws Exception {Hashtable <EncodeHintType, Objec T> hints = new Hashtable <EncodeHintType, Object> (); hints. put (EncodeHintType. ERROR_CORRECTION, ErrorCorrectionLevel. h); hints. put (EncodeHintType. CHARACTER_SET, CHARSET); hints. put (EncodeHintType. MARGIN, 1); BitMatrix bitMatrix = new MultiFormatWriter (). encode (content, BarcodeFormat. QR_CODE, QRCODE_SIZE, QRCODE_SIZE, hints); int width = bitMatrix. getWidth (); int height = bitMatrix. getHeight (); BufferedImag E image = new BufferedImage (width, height, BufferedImage. TYPE_INT_RGB); for (int x = 0; x <width; x ++) {for (int y = 0; y 

The QR code generated after running the main method:

3. Use Jquery. qrcode to generate a QR code

Download project usage:

Code download: https://github.com/izhongwei/two-dimemensionCode

 

Related Article

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.