首先下载Qrcode jar包 下载地址
public void tesclearRecttImgQr() throws IOException {
Qrcode x = new Qrcode();
//N代表数字,A代表a-z,B代表其他字符
x.setQrcodeEncodeMode('B');
//设置纠错等级
x.setQrcodeErrorCorrect('L');
//设置版本号(1-40)
x.setQrcodeVersion(3);
String qrDate = "https://developer.aliyun.com/";//地址
int width = 50;//宽度
int height = 50;//宽度
int pixoff = 0;//偏移量
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D gs = bufferedImage.createGraphics();
gs.setBackground(Color.WHITE);
gs.setColor(Color.BLACK);
gs.clearRect(0, 0, width, height);
byte[] d = qrDate.getBytes("UTF-8");
if (d.length > 0 && d.length < 120) {
boolean[][] s = x.calQrcode(d);
for (int i = 0; i < s.length; i++) {
for (int j = 0; j < s.length; j++) {
if (s[j][i]) {
gs.fillRect(j, i, 1, 1);
}
}
}
}
gs.dispose();
bufferedImage.flush();
ImageIO.write(bufferedImage, "png", new File("C:/图片地址.png"));
}