相信自己!

            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            26 隨筆 :: 3 文章 :: 13 評(píng)論 :: 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) 評(píng)論(0)  編輯  收藏 所屬分類: 網(wǎng)上轉(zhuǎn)載

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 株洲县| 景洪市| 吉木乃县| 凤冈县| 山东省| 澳门| 青冈县| 和林格尔县| 淮阳县| 吉水县| 东宁县| 河间市| 大港区| 西充县| 太仓市| 新河县| 阳西县| 叶城县| 宁明县| 甘南县| 嘉黎县| 四平市| 兖州市| 九龙城区| 五常市| 信阳市| 南华县| 宁蒗| 鄂托克旗| 临泉县| 诏安县| 阳新县| 唐河县| 叙永县| 独山县| 安岳县| 双峰县| 蕉岭县| 长海县| 乌恰县| 北碚区|