java 验证码 干扰点_java生成图片验证码二,加入透明颜色,各种干扰线,干扰点,干扰框,旋转,随机位置...

public classVerificationCode {

Random rand= newRandom();/*** 随机产生的加数和被加数*/

private int jiashu=0;private int beijiashu=0;/*** 随机产生的计算方式,0表示加,1表示减*/

private int js=0;private char[] aa={'零','壹','贰','叁','肆','伍','陆','柒','捌','玖'};private char[] action={'加','减'};private char[] jieguo={'等','是'};public static voidmain(String[] args) {

VerificationCode code=newVerificationCode();

JFrame jFrame=newJFrame();

jFrame.setBounds(400, 400, 250, 250);

ImageIcon img= newImageIcon(code.getVerificationCode2());

JLabel background= newJLabel(img);

jFrame.add(background);

jFrame.setVisible(true);

jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}/*** 第二种验证码的计算方式,两位数的加减法

*@return一个新的验证码图片*/

publicBufferedImage getVerificationCode2()

{int width=200;int height=100;int degree=0;//继续一共旋转的角度,方便最后的时候旋转回来

BufferedImage image = newBufferedImage(width, height,

BufferedImage.TYPE_4BYTE_ABGR);//获取图形上下文

Graphics g =image.getGraphics();//画随机干扰框

setSquareBackGround(g,width,height,5);//画干扰点//CreateRandomPoint(width, height,50,g,255);//随机画几条线//CreateRandomLine(width, height,2,g,255);//设定背景色

Color background=getColor(180);

g.setColor(background);

g.fillRect(0, 0, width, height);//画边框

g.setColor(background);

g.drawRect(0,0,width-1,height-1);//将认证码显示到图像中,如果要生成更多位的认证码

char[] content=getDrawContent2();int[] xs=getRadonWidths(width,content.length);int[] ys=getRadomHeights(height,content.length);for(int i=0;i

{ String s=content[i]+"";if(content[

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值