<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 495,comments - 227,trackbacks - 0
    <%@ page contentType="image/jpeg" import="java.awt.*,java.awt.image.*,java.util.*,com.sun.image.codec.jpeg.JPEGImageEncoder,com.sun.image.codec.jpeg.JPEGCodec,java.text.AttributedString,java.awt.font.TextLayout,java.awt.font.FontRenderContext,java.awt.geom.AffineTransform"%><%!private Random generator = new Random();
        
    private static char[] captchars = new char[] { 'a''b''c''d''e''2''3''4''5''6''7''8''g',
                
    'f''y''n''m''n''p''w''x','h','k','r','t','u','v' };

        
    /**  
         * 產生隨機字體  
         *  
         * 
    @return  
         
    */
        
    private Font getFont(int size) {
            Random random 
    = new Random();
            Font font[] 
    = new Font[5];
            font[
    0= new Font("Ravie", Font.PLAIN, size);
            font[
    1= new Font("Antique Olive Compact", Font.PLAIN, size);
            font[
    2= new Font("Forte", Font.PLAIN, size);
            font[
    3= new Font("Wide Latin", Font.PLAIN, size);
            font[
    4= new Font("Gill Sans Ultra Bold", Font.PLAIN, size);
            
    return font[random.nextInt(5)];
        }

        
    /**  
         * 隨機產生定義的顏色  
         *  
         * 
    @return  
         
    */
        
    private Color getRandColor() {
            Random random 
    = new Random();
            
    return new Color(random.nextInt(155)+100,random.nextInt(205)+50,random.nextInt(205)+50);//顏色較暗的一組
        }

        
    private void shear(Graphics g, int w1, int h1, Color color) {
            shearX(g, w1, h1, color);
            shearY(g, w1, h1, color);
        }

        
    private void shearX(Graphics g, int w1, int h1, Color color) {

            
    int period = generator.nextInt(2);

            
    boolean borderGap = true;
            
    int frames = 1;
            
    int phase = generator.nextInt(2);

            
    for (int i = 0; i < h1; i++) {
                
    double d = (double) (period >> 1)
                        
    * Math.sin((double) i / (double) period + (6.2831853071795862D * (double) phase) / (double) frames);
                g.copyArea(
    0, i, w1, 1, (int) d, 0);
                
    if (borderGap) {
                    g.setColor(color);
                    g.drawLine((
    int) d, i, 0, i);
                    g.drawLine((
    int) d + w1, i, w1, i);
                }
            }

        }

        
    private void shearY(Graphics g, int w1, int h1, Color color) {

            
    int period = generator.nextInt(40+ 10// 50; 

            
    boolean borderGap = true;
            
    int frames = 2;
            
    int phase = 1;//傾斜為1/2
            for (int i = 0; i < w1; i++) {
                
    double d = (double) (period >> 1)
                        
    * Math.sin((double) i / (double) period + (6.2831853071795862D * (double) phase) / (double) frames);
                g.copyArea(i, 
    01, h1, 0, (int) d);
                
    if (borderGap) {
                    g.setColor(color);
                    g.drawLine(i, (
    int) d, i, 0);
                    g.drawLine(i, (
    int) d + h1, i, h1);
                }
            }
        }

        
    private void drawThickLine(Graphics g, int x1, int y1, int x2, int y2, int thickness, Color c) {

            
    // The thick line is in fact a filled polygon 
            g.setColor(c);
            
    int dX = x2 - x1;
            
    int dY = y2 - y1;
            
    // line length 
            double lineLength = Math.sqrt(dX * dX + dY * dY);

            
    double scale = (double) (thickness) / (2 * lineLength);

            
    // The x and y increments from an endpoint needed to create a 
            
    // rectangle 
            double ddx = -scale * (double) dY;
            
    double ddy = scale * (double) dX;
            ddx 
    += (ddx > 0? 0.5 : -0.5;
            ddy 
    += (ddy > 0? 0.5 : -0.5;
            
    int dx = (int) ddx;
            
    int dy = (int) ddy;

            
    // Now we can compute the corner points 
            int xPoints[] = new int[4];
            
    int yPoints[] = new int[4];

            xPoints[
    0= x1 + dx;
            yPoints[
    0= y1 + dy;
            xPoints[
    1= x1 - dx;
            yPoints[
    1= y1 - dy;
            xPoints[
    2= x2 - dx;
            yPoints[
    2= y2 - dy;
            xPoints[
    3= x2 + dx;
            yPoints[
    3= y2 + dy;

            g.fillPolygon(xPoints, yPoints, 
    4);
        }
    %><%
        
    int ImageWidth = 120;
        
    int ImageHeight = 60;

        
    int car = captchars.length - 1;
        
    /** 
         * 產生隨機字符串 
         
    */
        String rand 
    = "";
        
    for (int i = 0; i < 4; i++) {
            rand 
    += captchars[generator.nextInt(car) + 1];
        }
        
    /** 
         * 放放Session 
         
    */
        request.getSession().setAttribute(
    "rand", rand);
        
    /** 
         * 得到輸出流 
         
    */
        JPEGImageEncoder encoder 
    = JPEGCodec.createJPEGEncoder(response.getOutputStream());

        BufferedImage bi 
    = new BufferedImage(ImageWidth + 10, ImageHeight, BufferedImage.TYPE_BYTE_INDEXED);

        Graphics2D graphics 
    = bi.createGraphics();

        
    /** 
         * 設置背景色 
         
    */
        graphics.setColor(Color.white);

        graphics.fillRect(
    00, bi.getWidth(), bi.getHeight());

        
    //graphics.setColor(Color.black);
        
    //AttributedString attstr = new AttributedString(rand);

        
    //TextLayout textTl = new TextLayout(rand, new Font("Courier", Font.BOLD, 70), new FontRenderContext(null,
            
    //    true, false));
        
    //AffineTransform textAt = graphics.getTransform();
        
    //graphics.setFont(new Font("Courier", Font.BOLD, 70));
        graphics.setFont(getFont(45));
        graphics.setColor(
    this.getRandColor());
        graphics.drawString(rand, 
    1055);
        
    //textTl.draw(graphics, 4, 60); 
        int w = bi.getWidth();
        
    int h = bi.getHeight();
        shear(graphics, w, h, Color.white);
        
    this.drawThickLine(graphics, 0, generator.nextInt(ImageHeight) + 1
         ImageWidth, generator.nextInt(ImageHeight) 
    + 12, getRandColor());
        
    this.drawThickLine(graphics, 0, generator.nextInt(ImageHeight) + 1
                 ImageWidth, generator.nextInt(ImageHeight) 
    + 12, getRandColor());
         

        
    //response.setContentType("image/jpg");

        encoder.encode(bi);
    %>
    posted on 2009-09-01 14:49 SIMONE 閱讀(854) 評論(1)  編輯  收藏

    FeedBack:
    # re: jsp頁面生成扭曲的驗證碼[未登錄]
    2011-07-12 10:46 | test
    給力。。。。  回復  更多評論
      

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


    網站導航:
     
    主站蜘蛛池模板: 亚洲乱码一二三四五六区| 久热综合在线亚洲精品| 亚洲欧美日韩中文高清www777| 最近中文字幕完整版免费高清| 亚洲AV无码精品色午夜果冻不卡| 中国极品美軳免费观看| 亚洲乱码一区二区三区在线观看| 国产一区二区三区免费观在线| 亚洲熟妇av一区二区三区| 精品成人免费自拍视频| 亚洲福利视频网址| 免费一本色道久久一区| 亚洲国产AV一区二区三区四区| 国产乱子伦精品免费女| 精品97国产免费人成视频| 国产av天堂亚洲国产av天堂 | 美女18一级毛片免费看| 免费一级做a爰片性色毛片| 国产特黄特色的大片观看免费视频| 中文字幕精品亚洲无线码一区| 久草免费福利资源站| 亚洲一级大黄大色毛片| 日韩免费无砖专区2020狼| 九九九国产精品成人免费视频| 亚洲AV永久无码精品一百度影院| 中文字幕在线免费| 亚洲爆乳AAA无码专区| 国产亚洲美日韩AV中文字幕无码成人| 免费高清国产视频| 亚洲精品国产国语| 亚洲中文字幕成人在线| 97在线视频免费播放| WWW亚洲色大成网络.COM| 日本红怡院亚洲红怡院最新| 成人免费在线看片| 午夜成人无码福利免费视频| 久久青青成人亚洲精品| 国产成人免费福利网站| 十八禁无码免费网站| 综合一区自拍亚洲综合图区| 激情内射亚洲一区二区三区|