你的位置:首页 > 软件开发 > Java > java生成二维码

java生成二维码

发布时间:2016-08-22 10:00:08
@RequestMapping(value="/123.html") public void yaz(HttpServletResponse response,HttpServletRequest request) throws Exception{ ...
@RequestMapping(value="/123.html")  public void yaz(HttpServletResponse response,HttpServletRequest request) throws Exception{        request.setCharacterEncoding("UTF-8");    response.setCharacterEncoding("text/html;charset=utf-8");    int width=80;int height=40;    //画板    BufferedImage b =new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);    //工具    Graphics g= b.getGraphics();        g.setColor(new Color(40, 200, 255));    g.fillRect(0, 0, width, height);        char[] ch="QWERTYUIOPASDFGHJKLZXCVBNM1234567890".toCharArray();    Random random = new Random();    int len = ch.length,index;    StringBuffer sb = new StringBuffer();    for (int i = 0; i < 4; i++) {      index = random.nextInt(len);      g.setColor(new Color(random.nextInt(88), random.nextInt(188), random.nextInt(255)));      g.setFont(new Font("微软雅黑", Font.BOLD, 18));      g.drawString(ch[index]+"", i*15+3, 18);      sb.append(ch[index]);        }    //干扰线    for(int i=1;i<10000;i++){      g.setColor(new Color(random.nextInt(88), random.nextInt(188), random.nextInt(255)));      g.drawLine(random.nextInt(i*3+2), random.nextInt(i*5+1), random.nextInt(i*3+1),random.nextInt(i*9));    }        //结束    g.dispose();    b.flush();    //保存    request.getSession().setAttribute("yzm", sb.toString());    try {      //输出图片到页面      ImageIO.write(b, "png", response.getOutputStream());    } catch (IOException e) {          }          }

原标题:java生成二维码

关键词:JAVA

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。