标签:指定 phi 转化 nbsp and bsp next wstring ext
1 ///创建图像缓冲区 2 BufferedImage bi = new BufferedImage(68, 22, BufferedImage.TYPE_INT_RGB); 3 //通过缓冲区创建一个画布 4 Graphics g = bi.getGraphics(); 5 Color c = new Color(200, 150, 255); //创建颜色 6 //为画布创建背景颜色 7 g.setColor(c); 8 g.fillRect(0, 0, 68, 22); //fillRect:填充指定的矩形 9 //转化为字符型的数组 10 char[] ch = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toCharArray(); 11 Random r = new Random(); 12 int len = ch.length; 13 int index; //index用于存放随机数字 14 StringBuffer sb = new StringBuffer(); 15 for (int i = 0; i < 4; i++) { 16 //产生随机数字 17 index = r.nextInt(len); 18 //设置颜色 19 g.setColor(new Color(r.nextInt(88), r.nextInt(188), r.nextInt(255))); 20 //画数字以及数字的位置 21 g.drawString(ch[index] + "", (i * 15) + 3, 18); 22 sb.append(ch[index]); 23 } 24 25 request.getSession().setAttribute("piccode", sb.toString()); 26 ImageIO.write(bi, "JPG", response.getOutputStream());
标签:指定 phi 转化 nbsp and bsp next wstring ext
原文地址:http://www.cnblogs.com/tooyoung/p/7739844.html