相信自己!

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            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 北極雪 閱讀(329) 評論(0)  編輯  收藏 所屬分類: 網(wǎng)上轉(zhuǎn)載

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 伊通| 松溪县| 诸暨市| 东平县| 西畴县| 罗江县| 浑源县| 三江| 长春市| 沅陵县| 古丈县| 邵阳市| 高要市| 安徽省| 余姚市| 唐山市| 沈阳市| 改则县| 新田县| 那曲县| 桐城市| 乐至县| 泾川县| 高安市| 蓝田县| 兴和县| 安福县| 沅江市| 吉木萨尔县| 光泽县| 汝城县| 中方县| 上蔡县| 红安县| 汤阴县| 台安县| 红桥区| 裕民县| 措勤县| 霍邱县| 新绛县|