• 空心验证码(定制) 悟寰轩


     1    Graphics2D graphics = (Graphics2D) image.getGraphics();
     2         graphics.setColor(color);
     3         RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
     4         hints.add(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
     5         graphics.setRenderingHints(hints);
     6         FontRenderContext frc = graphics.getFontRenderContext();
     7         
     8         char[] wordChars = text.toCharArray();
     9         int startPosY = 40;
    10         int startPosX = 60;
    11         Random random = new Random();
    12         for (int i = 0; i < wordChars.length; i++) {
    13             graphics.setFont(fonts[0]);
    14             char[] charToDraw = new char[] { wordChars[i] };
    15             GlyphVector fontGV = fonts[0].createGlyphVector(frc, charToDraw);
    16             Shape textShape = fontGV.getOutline();
    17             AffineTransform rotate45 = AffineTransform.getRotateInstance(30 * Math.PI, 0, 0);
    18             Shape rotatedText = rotate45.createTransformedShape(textShape);
    19             graphics.translate(startPosX, startPosY);
    20             graphics.draw(rotatedText);
    21             startPosX = (random.nextInt(3) + 1) * 10;
    22             startPosY = (random.nextInt(3) + 1);
    23         }
    24 
    25   graphics.dispose();

    扣空心,只支持一个一个字符的~,多个字符需要循环draw.

  • 相关阅读:
    实验五
    实验四
    实验三
    实验二
    寄存器(内存访问)
    实验一
    寄存器
    Mermaid 绘图总结
    电脑查看系统版本
    _ZNote_Chrom_插件_Chrom运行Android软件_APK
  • 原文地址:https://www.cnblogs.com/sunxucool/p/3123544.html
Copyright © 2020-2023  润新知