code: public static BufferedImage genRandomImage(String rand, int size) {
  		BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
  		Font font = new Font("Courier New", Font.BOLD, size);
  
  		// 获取图形上下文
  		Graphics2D g = image.createGraphics();
  		Rectangle2D rect = font.getStringBounds(rand, g.getFontRenderContext());
  
  		// 设定背景色
  		g.setColor(Color.white);
  		g.fillRect(0, 0, image.getWidth(), image.getHeight());
  
  		// 将验证码显示到图象中
  		g.setColor(Color.black);
  		g.setFont(font);
  		g.drawString(rand, 2, (int) rect.getHeight() - 2);
  
  		// 图象生效
  		g.dispose();
  
  		// 随机产生干扰点
  		for (int i = 0; i < 500; i++)
  			image.setRGB(m_ran.nextInt(image.getWidth()), m_ran.nextInt(image.getWidth()), 0);
  
  		return twistImage(image, (int) rect.getWidth() + 4, (int) rect.getHeight() + 4, true);
  	}
docs: 生成验证码图片
  
  @param rand
  @param size
  @return