添加随机线条
===============================
Random random = new Random();
g.setColor(Color.RED);// 设置线条的颜色
for (int i = 0; i < 25; i++) {
int x=random.nextInt(100);
int y=random.nextInt(100);
int x1=random.nextInt(100);
int y1=random.nextInt(100);
int s1=random.nextInt(256);
int s2=random.nextInt(256);
int s3=random.nextInt(256);
g.setColor(new Color(x,y,x1));
g.drawLine(x,y,x1,y1);
}
===============================
//绘制噪点
float yawpRate =0.05f;// 噪声率
int area = (int) (yawpRate *WIDTH *HEIGHT);
for (int i =0; i < area; i++) {
int x = random.nextInt(WIDTH);
int y = random.nextInt(HEIGHT);
int rgb = random.nextInt(256);
img.setRGB(x, y, rgb);
}
生成随机验证码
===============================
public StringrandomString(int count){
StringBuilder buffer1 =new StringBuilder();
String val="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
Random r =new Random();
for(int i=0;i
int index=r.nextInt(val.length());
char c=val.charAt(index);
buffer1.append(c+" ");
}
return buffer1.toString();
}
效果
=========================