美文网首页
QR Code 生成二维码

QR Code 生成二维码

作者: 一个javaClass | 来源:发表于2016-11-05 22:19 被阅读0次

Qrcode x =newQrcode();

x.setQrcodeErrorCorrect('M');

x.setQrcodeEncodeMode('B');

x.setQrcodeVersion(7);

intwidth =67+12*(7-1);

intheight =67+12*(7-1);

String qrData ="hello hello";

BufferedImage bufferedImage =newBufferedImage(width,height,BufferedImage.TYPE_INT_RGB);

Graphics2D gs = bufferedImage.createGraphics();

gs.setBackground(Color.WHITE);

gs.setColor(Color.BLACK);

gs.clearRect(0,0,width,height);

intpixoff =2;

byte[] d =qrData.getBytes("gb2312");

if(d.length>0&&d.length<=120){

boolean[][] s = x.calQrcode(d);

for(inti=0;i

for(intj=0;j

if(s[j][i]){

gs.fillRect(j*3+pixoff,i*3+pixoff,3,3);

}

}

gs.dispose();

bufferedImage.flush();

ImageIO.write(bufferedImage,"png",newFile("d:/qrcode.png"));

相关文章

网友评论

      本文标题:QR Code 生成二维码

      本文链接:https://www.haomeiwen.com/subject/hdgejttx.html