标题: 不是原创 [打印本页] 作者: 李啸 时间: 2012-5-9 22:16 标题: 不是原创 public class Imagetest extends HttpServlet {
//将要添加进图片的字符当然这些字符是被随机进去的
public static final char[] CHARS={'a','b','c','d','e','f','g','h','i','j','k','m','n','o','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','J','K','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//创建随机对象Random对象
public static Random random=new Random();
//获取随机字符的方法返回字符串
public static String getRandomString(){
StringBuilder builder=new StringBuilder();
for (int i = 0; i < 6; i++) {//每次要六个字符
builder.append(CHARS[random.nextInt(CHARS.length)]);
}
return builder.toString();
}
//图片背景的颜色
public static Color getColor(){
return new Color(random.nextInt(255),random.nextInt(255),random.nextInt(255));
}
//获取当前图片的反色为了让图片颜色和图片的颜色形成鲜明的对比
public static Color getReverseColor(Color c){
return new Color(255-c.getRed(),255-c.getBlue(),255-c.getGreen());
}