Business Card Two-dimensional code generation example

Source: Internet
Author: User
Tags vcard

Description: This instance is an instance of generating a two-dimensional code card

    1. Need Qrcode_swetake.jar

    2. The next step is to introduce the jar package into the project so that the two-dimensional code can be generated


String content= "begin:vcard\n"

+ "version:3.0\n"

+ "FN: Name \ n"

+ "TEL; CELL; VOICE: Phone \ n "

+ "TEL; work; VOICE: Phone \ n "

+ "EMAIL; pref;internet: Mail \ n "

+ "URL: URL \ n"

+ "title: Position \ n"

+ "ROLE: Title \ n"

+ "ADR; work; POSTAL: address; \ n "

+ "ORG: Confidential \ n"

+ "note:qq:\n"

+ "End:vcard";


----------------------------------------------

Package Com.code;

Import Java.awt.Color;

Import Java.awt.Graphics2D;

Import Java.awt.image.BufferedImage;

Import Java.io.File;

Import java.io.IOException;

Import java.io.UnsupportedEncodingException;

Import Javax.imageio.ImageIO;

Import Com.swetake.util.Qrcode;


public class Qrcodetest {


public static void Main (string[] args) throws unsupportedencodingexception{

QRCode qrcode = new QRCode ();

//set indicates that the get is set to get

//Error correction rate mode version

//Set mode to binary

qrcode.setqrcodeencodemode (' B ');

//Set error correction rate

qrcode.setqrcodeerrorcorrect (' M ');

//Set version number 1-40

qrcode.setqrcodeversion (12);

//Patents, Java made a product has its own characteristics. Application for property rights and patents

String content= "begin:vcard\n"

+ "version:3.0\n"

+ "FN: Name \ n"

+ "TEL; CELL; VOICE: Phone \ n "

+ "TEL; work; VOICE: Phone \ n "

+ "EMAIL; pref;internet: Mail \ n "

+ "url: URL \ n"

+ "title: Position \ n"

+ "ROLE: Title \ n"

+ "ADR; work; POSTAL: address; \ n "

+ "ORG: Confidential \ n"

+ "note:qq:\n"

+ "End:vcard";

Size (Flexible change according to the size of the two-dimensional code information)

int width=330,height=330;

bufferedimage bufimage = new BufferedImage (width, height, bufferedimage.type_int_rgb);

//Create drawing Tools

graphics2d grap = Bufimage.creategraphics ();

Grap.setbackground (color.white);

Grap.setbackground (New Color (255, 255, 255));

Grap.clearrect (0,0,width,height);

Grap.setcolor (new Color (0, 0, 255));

//boolean is only two or true or false

boolean[][] qrcodebytes = Qrcode.calqrcode (Content.getbytes ("UTF-8"));

int qrcodewidth=5;

for (int i = 0;i<qrcodebytes.length;i++) {

for (int j = 0;j<qrcodebytes.length;j++) {

if (Qrcodebytes[j][i]) {

grap.fillrect (j*qrcodewidth, I*qrcodewidth, Qrcodewidth, qrcodewidth);

}

}

}

try {

Grap.drawimage (Imageio.read (New File ("D:\\as.png")), 50,50,50,50,null);

Grap.drawimage (Imageio.read (New File ("D:\\as.png")), 50,190,40,40,null);

Grap.drawimage (Imageio.read (New File ("D:\\code/dzq.jpg")), 125,50,80,80,null);

Grap.drawimage (Imageio.read (New File ("D:\\code/wn.png")), 145,190,40,40,null);

grap.dispose ();

Bufimage.flush ();

imageio.write (bufimage, "JPEG", New File ("D:\\code/new-card-2015.png"));

System.out.println ("created successfully! ");

} catch (IOException e) {

e.printstacktrace ();

}

}

}


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/73/A7/wKioL1YDcmzjIfkmAAJJ_Rdv2Bc708.jpg "title=" Dzq-blog.png "alt=" Wkiol1ydcmzjifkmaajj_rdv2bc708.jpg "/>

This article from "Wennuanyiran" blog, reproduced please contact the author!

Business Card Two-dimensional code generation example

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.