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"));
网友评论