<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      驗(yàn)證碼工具類【復(fù)制】

      public class getRandomPictrue extends BaseAction implements IgnoreAction {
      	
      	private ByteArrayInputStream image;// 圖像  
          private String str;// 驗(yàn)證碼  
          private static final int WIDTH = 80;  
          private static final int HEIGHT = 20;
      	/**
      	 * 
      	 */
      	private static final long serialVersionUID = -6098322779401546263L;
      
      	public String getRandomPictrue() {  
      		int width = 120;  
              int height = 30;
              
           // 步驟一 繪制一張內(nèi)存中圖片  
              BufferedImage bufferedImage = new BufferedImage(width, height,  
                      BufferedImage.TYPE_INT_RGB);
              
           // 步驟二 圖片繪制背景顏色 ---通過繪圖對(duì)象  
              Graphics graphics = bufferedImage.getGraphics();// 得到畫圖對(duì)象 --- 畫筆
              
           // 繪制任何圖形之前 都必須指定一個(gè)顏色  
              graphics.setColor(getRandColor(200, 250));  
              graphics.fillRect(0, 0, width, height);   
           // 步驟三 繪制邊框  
              graphics.setColor(Color.WHITE);  
              graphics.drawRect(0, 0, width - 1, height - 1);
           // 步驟四 四個(gè)隨機(jī)數(shù)字  
              Graphics2D graphics2d = (Graphics2D) graphics;     
            
           // 設(shè)置輸出字體  
              graphics2d.setFont(new Font("宋體", Font.BOLD, 18));  
           
              String words ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
              //String words ="1234567890";
              Random random = new Random();// 生成隨機(jī)數(shù)
              
           // 定義StringBuffer   
              StringBuffer sb = new StringBuffer();
           // 定義x坐標(biāo)  
              int x = 10;    
             
              for (int i = 0; i < 4; i++) {  
                  // 隨機(jī)顏色  
                  graphics2d.setColor(new Color(20 + random.nextInt(110), 20 + random  
                          .nextInt(110), 20 + random.nextInt(110)));  
                  // 旋轉(zhuǎn) -30 --- 30度  
                  int jiaodu = random.nextInt(60) - 30;  
                  // 換算弧度  
                  double theta = jiaodu * Math.PI / 180;  
       
                  // 生成一個(gè)隨機(jī)數(shù)字  
                  int index = random.nextInt(words.length()); // 生成隨機(jī)數(shù) 0 到 length - 1  
                  // 獲得字母數(shù)字  
                  char c = words.charAt(index);  
                  sb.append(c);  
                  // 將c 輸出到圖片  
                  graphics2d.rotate(theta, x, 20);  
                  graphics2d.drawString(String.valueOf(c), x, 20);  
                  graphics2d.rotate(-theta, x, 20);  
                  x += 30;  
              }  
              
           // 將生成的字母存入到session中  
              ServletActionContext.getRequest().getSession().setAttribute("checkcode", sb.toString());
              
           // 步驟五 繪制干擾線  
              graphics.setColor(getRandColor(160, 200));  
              int x1;  
              int x2;  
              int y1;  
              int y2;  
              for (int i = 0; i < 30; i++) {  
                  x1 = random.nextInt(width);  
                  x2 = random.nextInt(12);  
                  y1 = random.nextInt(height);  
                  y2 = random.nextInt(12);  
                  graphics.drawLine(x1, y1, x1 + x2, x2 + y2);  
              }    
              
           // 將上面圖片輸出到瀏覽器 ImageIO  
              graphics.dispose();// 釋放資源  
              try {
      			ImageIO.write(bufferedImage, "jpg", ServletActionContext.getResponse().getOutputStream());
      		} catch (IOException e) {
      			// TODO Auto-generated catch block
      			e.printStackTrace();
      		}
              
              return NONE;
      	}
      	/** 
           * 功能:設(shè)置第一種驗(yàn)證碼的屬性 
           */  
          public void initNumVerificationCode(BufferedImage image) {  
        
              Random random = new Random(); // 生成隨機(jī)類  
              Graphics g = initImage(image, random);  
              String sRand = "";  
              for (int i = 0; i < 4; i++) {  
                  String rand = String.valueOf(random.nextInt(10));  
                  sRand += rand;  
                  // 將認(rèn)證碼顯示到圖象中  
                  g.setColor(new Color(20 + random.nextInt(110), 20 + random  
                          .nextInt(110), 20 + random.nextInt(110)));  
                  // 調(diào)用函數(shù)出來的顏色相同,可能是因?yàn)榉N子太接近,所以只能直接生成  
                  g.drawString(rand, 13 * i + 6, 16);  
              }  
              this.setStr(sRand);/* 賦值驗(yàn)證碼 */  
              // 圖象生效  
              g.dispose();  
              this.setImage(drawImage(image));  
          }  
          /** 
           * 功能:設(shè)置第二種驗(yàn)證碼屬性 
           */  
          public void initLetterAndNumVerificationCode(BufferedImage image) {  
        
              Random random = new Random(); // 生成隨機(jī)類  
              Graphics g = initImage(image, random);  
              String[] letter = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J",  
                      "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",  
                      "W", "X", "Y", "Z" };  
              String sRand = "";  
              for (int i = 0; i < 4; i++) {  
                  String tempRand = "";  
                  if (random.nextBoolean()) {  
                      tempRand = String.valueOf(random.nextInt(10));  
                  } else {  
                      tempRand = letter[random.nextInt(25)];  
                      if (random.nextBoolean()) {// 隨機(jī)將該字母變成小寫  
                          tempRand = tempRand.toLowerCase();  
                      }  
                  }  
                  sRand += tempRand;  
                  g.setColor(new Color(20 + random.nextInt(10), 20 + random  
                          .nextInt(110), 20 + random.nextInt(110)));  
                  g.drawString(tempRand, 13 * i + 6, 16);  
              }  
              this.setStr(sRand);/* 賦值驗(yàn)證碼 */  
              g.dispose(); // 圖象生效  
              this.setImage(drawImage(image));  
          }  
        
          /** 
           * 功能:設(shè)置第三種驗(yàn)證碼屬性 即:肆+?=24 
           */  
          public void initChinesePlusNumVerificationCode(BufferedImage image) {  
              String[] cn = { "壹", "貳", "叁", "肆", "伍", "陸", "柒", "捌", "玖", "拾" };  
              Random random = new Random(); // 生成隨機(jī)類  
              Graphics g = initImage(image, random);  
              int x = random.nextInt(10) + 1;  
              int y = random.nextInt(30);  
              this.setStr(String.valueOf(y));  
              g.setFont(new Font("楷體", Font.PLAIN, 14));// 設(shè)定字體  
              g.setColor(new Color(20 + random.nextInt(10), 20 + random.nextInt(110),  
                      20 + random.nextInt(110)));  
              g.drawString(cn[x - 1], 1 * 1 + 6, 16);  
              g.drawString("+", 22, 16);  
              g.drawString("?", 35, 16);  
              g.drawString("=", 48, 16);  
              g.drawString(String.valueOf(x + y), 61, 16);  
              g.dispose(); // 圖象生效  
              this.setImage(drawImage(image));  
        
          }  
        
          public Graphics initImage(BufferedImage image, Random random) {  
              Graphics g = image.getGraphics(); // 獲取圖形上下文  
              g.setColor(getRandColor(200, 250));// 設(shè)定背景色  
              g.fillRect(0, 0, WIDTH, HEIGHT);  
              g.setFont(new Font("Times New Roman", Font.PLAIN, 14));// 設(shè)定字體  
              g.setColor(getRandColor(160, 200)); // 隨機(jī)產(chǎn)生165條干擾線,使圖象中的認(rèn)證碼不易被其它程序探測(cè)到  
              for (int i = 0; i < 165; i++) {  
                  int x = random.nextInt(WIDTH);  
                  int y = random.nextInt(HEIGHT);  
                  int xl = random.nextInt(12);  
                  int yl = random.nextInt(12);  
                  g.drawLine(x, y, x + xl, y + yl);  
              }  
              return g;  
          }  
        
          public ByteArrayInputStream drawImage(BufferedImage image) {  
              ByteArrayInputStream input = null;  
              ByteArrayOutputStream output = new ByteArrayOutputStream();  
              try {  
                  ImageOutputStream imageOut = ImageIO  
                          .createImageOutputStream(output);  
                  ImageIO.write(image, "JPEG", imageOut);  
                  imageOut.close();  
                  input = new ByteArrayInputStream(output.toByteArray());  
              } catch (Exception e) {  
                  System.out.println("驗(yàn)證碼圖片產(chǎn)生出現(xiàn)錯(cuò)誤:" + e.toString());  
              }  
              return input;  
          }  
        
          /* 
           * 功能:給定范圍獲得隨機(jī)顏色 
           */  
          private Color getRandColor(int fc, int bc) {  
              Random random = new Random();  
              if (fc > 255)  
                  fc = 255;  
              if (bc > 255)  
                  bc = 255;  
              int r = fc + random.nextInt(bc - fc);  
              int g = fc + random.nextInt(bc - fc);  
              int b = fc + random.nextInt(bc - fc);  
              return new Color(r, g, b);  
          }  
        
          /** 
           * 功能:獲取驗(yàn)證碼的字符串值 
           *  
           * @return 
           */  
          public String getVerificationCodeValue() {  
              return this.getStr();  
          }  
        
          /** 
           * 功能:取得驗(yàn)證碼圖片 
           *  
           * @return 
           */  
          public ByteArrayInputStream getImage() {  
              return this.image;  
          }  
        
          public String getStr() {  
              return str;  
          }  
        
          public void setStr(String str) {  
              this.str = str;  
          }  
        
          public void setImage(ByteArrayInputStream image) {  
              this.image = image;  
          } 
          
          private void mian() {
      		// TODO Auto-generated method stub
          	System.out.println(getRandomPictrue());
      	}
      }
      

       

      posted @ 2020-04-13 09:42  超神之巔  閱讀(317)  評(píng)論(0)    收藏  舉報(bào)
      主站蜘蛛池模板: 人妻中文字幕av资源站| 欧美人与动牲交A免费观看| 亚洲av成人在线一区| 中国女人熟毛茸茸A毛片| 夜鲁鲁鲁夜夜综合视频| 日韩一区二区三区av在线| 亚洲一区二区经典在线播放| 东乡族自治县| 尤物yw193无码点击进入| 欧美日韩精品久久久免费观看| 激情内射亚洲一区二区三区| 性男女做视频观看网站| 少妇无套内射中出视频| 在线综合亚洲欧洲综合网站| 老太脱裤让老头玩ⅹxxxx| 国产av熟女一区二区三区| 亚洲精品久久麻豆蜜桃| 国产精品自拍自在线播放| 临桂县| 日本不卡片一区二区三区| 最新国产AV最新国产在钱| 又色又爽又黄的视频网站| 亚洲国产综合av在线观看| 国精品无码一区二区三区在线看| 亚洲乱码精品久久久久..| 万宁市| 亚洲第一精品一二三区| 少妇人妻偷人精品免费| 中国熟妇毛多多裸交视频| 无码av片在线观看免费| 亚洲av永久无码精品天堂久久| 国产精品国产亚洲看不卡| 91中文字幕一区在线| 国产仑乱无码内谢| 国产一区二区日韩在线| 中文国产乱码在线人妻一区二区| 国产国产人免费人成免费| 亚洲国产日韩欧美一区二区三区| 国产成人精品午夜二三区| 日本一区不卡高清更新二区| 成人亚欧欧美激情在线观看|