import org.apache.commons.lang.RandomStringUtils;
public class Test {
private static int WIDTH = 120;
private static int HEIGHT = 40;
private static int LENGTH = 5;
private final static Random random = new Random();
private static void _Render(String text, OutputStream out, int width, int height) throws IOException {
BufferedImage bi = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphics2D g = (Graphics2D)bi.getGraphics();
g.setColor(Color.WHITE);
g.fillRect(0,0,width,height);
//g.setColor(Color.RED);
//g.drawRect(1,1,width-2,height-2);
for(int i=0;i<10;i++){
g.setColor(_GetRandColor(150, 250));
g.drawOval(random.nextInt(110), random.nextInt(24), 5+random.nextInt(10), 5+random.nextInt(10));
}
Font mFont = new Font("Arial", Font.ITALIC, 28);
g.setFont(mFont);
g.setColor(_GetRandColor(10,240));
g.drawString(text, 10, 30);
ImageIO.write(bi, "png", out);
}
private static Color _GetRandColor(int fc,int bc){//给定范围获得随机颜色
if (fc > 255) fc = 255;
if (bc > 255) bc = 255;
int r = fc + random.nextInt(bc - fc);
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余1页未读,立即下载