使用QrCode生成二维码

    xiaoxiao2021-03-29  60

    1.首先下载Qrcode.jar和Qrcodeb.jar放入到项目的lib目录下链接:http://pan.baidu.com/s/1nuMrVM5 密码:rt8z

    2.编写Java代码

    @RequestMapping(“/shengchengtesterweima”) public void shengchengtesterweima(HttpServletRequest request,HttpServletResponse response,int testid) throws Exception{

    Qrcode x=new Qrcode(); x.setQrcodeErrorCorrect('M');//纠错等级 x.setQrcodeEncodeMode('B');//其他字符 x.setQrcodeVersion(7);//版本号 String qrData="http://www.baidu.com";//放你自己的连接 int width=67+12*(7-1); int height=67+12*(7-1);//7为版本号 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); int pixoff=2;//偏移量 byte[] d =qrData.getBytes("gb2312"); if (d.length>0 && d.length <120){ boolean[][] s = x.calQrcode(d); for (int c=0;c<s.length;c++){ for (int j=0;j<s.length;j++){ if (s[j][c]) { gs.fillRect(j*3+pixoff,c*3+pixoff,3,3); } } } } gs.dispose(); bufferedImage.flush(); ImageIO.write(bufferedImage, "jpg", response.getOutputStream());

    }

    3.在前端jsp页面接收二维码图片

    转载请注明原文地址: https://ju.6miu.com/read-665012.html

    最新回复(0)