標籤:郵箱 二維碼 content 姓名
說明:此執行個體為產生二維碼名片的執行個體
需要Qrcode_swetake.jar
接下來將jar包引入到項目中,就可以實現二維碼產生了
String content="BEGIN:VCARD\n"
+ "VERSION:3.0\n"
+ "FN:姓名\n"
+ "TEL;CELL;VOICE:手機\n"
+ "TEL;WORK;VOICE:手機\n"
+ "EMAIL;PREF;INTERNET:郵箱\n"
+ "URL:網址\n"
+ "TITLE:職位\n"
+ "ROLE: 職稱\n"
+ "ADR;WORK;POSTAL:地址;\n"
+ "ORG:保 密\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 表示設定 get 表示擷取
//錯誤修正率 模式 版本
//設定模式為二進位
qrcode.setQrcodeEncodeMode(‘B‘);
//設定錯誤修正率
qrcode.setQrcodeErrorCorrect(‘M‘);
//設定版本號碼 1-40
qrcode.setQrcodeVersion(12);
//專利 , Java作出一個產品 有自己特色。申請產權和專利
String content="BEGIN:VCARD\n"
+ "VERSION:3.0\n"
+ "FN:姓名\n"
+ "TEL;CELL;VOICE:手機\n"
+ "TEL;WORK;VOICE:手機\n"
+ "EMAIL;PREF;INTERNET:郵箱\n"
+ "URL:網址\n"
+ "TITLE:職位\n"
+ "ROLE: 職稱\n"
+ "ADR;WORK;POSTAL:地址;\n"
+ "ORG:保 密\n"
+ "NOTE:QQ:\n"
+ "END:VCARD";
//尺寸(根據二維碼資訊量的大小靈活更改)
int width=330,height=330;
BufferedImage bufImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
//建立畫圖工具
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 只有兩個 要麼true 要麼是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("建立成功!");
} 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" />
本文出自 “wennuanyiran” 部落格,轉載請與作者聯絡!
名片二維碼產生執行個體