QR Code 生成二维码

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"));

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容