相信自己!

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            26 隨筆 :: 3 文章 :: 13 評論 :: 0 Trackbacks
          <%@ page language="java" import="java.util.*" %>
          <%@ page contentType="image/jpeg" import="java.awt.*,java.awt.image.*,javax.imageio.*" %>
          <%@ page import="java.io.OutputStream" %>
          <%!
          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);
                  }
          %>
          <%
          response.setHeader(
          "Pragma","No-cache");
          response.setHeader(
          "Cache-Control","no-cache");
          response.setDateHeader(
          "Expires"0);

          int width=60, height=20;
          BufferedImage image 
          = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
          OutputStream os
          =response.getOutputStream();
          Graphics g 
          = image.getGraphics();

          Random random 
          = new Random();


          g.setColor(getRandColor(
          200,250));
          g.fillRect(
          00, width, height);

          g.setFont(
          new Font("Times New Roman",Font.PLAIN,18));

          g.setColor(getRandColor(
          160,200));
          for (int i=0;i<155;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);
          }

          String sRand
          ="";
          for (int i=0;i<4;i++){
              String rand
          =String.valueOf(random.nextInt(10));
              sRand
          +=rand;

              g.setColor(
          new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110)));
              g.drawString(rand,
          13*i+6,16);
          }

          session.setAttribute(
          "rand",sRand);

          g.dispose();

          ImageIO.write(image, 
          "JPEG",os);
          os.flush();
          os.close();
          os
          =null;
          response.flushBuffer();
          out.clear();
          out 
          = pageContext.pushBody();
          %>
          posted on 2008-02-13 09:46 北極雪 閱讀(334) 評論(0)  編輯  收藏 所屬分類: 網上轉載

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 滦南县| 车致| 台南县| 昌邑市| 山东省| 正定县| 望城县| 墨竹工卡县| 合水县| 临汾市| 舞阳县| 镇巴县| 淳化县| 黔东| 尼勒克县| 台前县| 湟源县| 玉龙| 阿合奇县| 定安县| 南昌县| 汉沽区| 盐源县| 阿拉善盟| 博客| 平顶山市| 齐齐哈尔市| 白水县| 嵊州市| 龙门县| 宁乡县| 通州区| 益阳市| 崇信县| 鄂托克前旗| 株洲县| 西平县| 梁平县| 西青区| 清苑县| 武川县|