maven 依赖:
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>3.2.0</version>
example:
public class QRcreate {
public static void main(String[] args) {
Map<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
// 指定纠错等级
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
// 指定编码格式
hints.put(EncodeHintType.CHARACTER_SET, "UTF8");
try {
// BitMatrix bitMatrix = new MultiFormatWriter().encode("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxe419257ba60d4cab&redirect_uri=http%3A%2F%2Fwww.evertalk.cn%2Febill%2Fwx%2Fcommen&response_type=code&scope=snsapi_base&state=A#wechat_redirec",BarcodeFormat.QR_CODE, 500, 500,hints);
BitMatrix bitMatrix = new MultiFormatWriter().encode("http://dwz.cn/5i9lxQ",BarcodeFormat.QR_CODE, 500, 500,hints);
MatrixToImageWriter.writeToStream(bitMatrix, "png", new FileOutputStream("sss.png"));
} catch (Exception e) {
e.printStackTrace();
}
}
}