相信自己!

            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)  編輯  收藏 所屬分類: 網上轉載

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


          網站導航:
           
          主站蜘蛛池模板: 元江| 乌鲁木齐县| 苏州市| 大新县| 依兰县| 贵南县| 伊金霍洛旗| 宝丰县| 田东县| 房山区| 清徐县| 登封市| 罗甸县| 新闻| 镇江市| 霞浦县| 郓城县| 登封市| 怀安县| 浦江县| 托克托县| 英超| 沁阳市| 鸡泽县| 永宁县| 仙桃市| 肃宁县| 灵川县| 海阳市| 武威市| 铁力市| 同德县| 建宁县| 宜宾市| 鹿泉市| 南昌县| 菏泽市| 永定县| 郑州市| 云霄县| 呼玛县|