标签:功能 ima nts char int ace void 捕捉异常 编码
// 生成二维码
public class GreatQrCode {
public static void main(String[] args) {
// 定义一些基本参数
int width = 300;
int height = 300;
String format = "png";
String content = "http://www.cnblogs.com/wshuo/";
// 定义二维码参数 使用map 和MatrixToImageWriter
HashMap hints = new HashMap();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
// 设置二维码的容错等级
hints.put(EncodeHintType.ERROR_CORRECTION,ErrorCorrectionLevel.M);
hints.put(EncodeHintType.MARGIN, 2);
// 定义二维码的格式 BarcodeFormat 来定义二维码 ; 需要捕捉异常
try {
BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height, hints);
File file = new File("D:/img.png");
MatrixToImageWriter.writeToFile(bitMatrix, format, file);
System.out.println("dangkl");
} catch (Exception e) {
e.printStackTrace();
}
}
}
标签:功能 ima nts char int ace void 捕捉异常 编码
原文地址:http://www.cnblogs.com/wshuo/p/7742033.html