class SimpleCaptchaGenerator {

	public CaptchaResult generate(CaptchaSettings settings){
		int width = settings.getWidth();
		int height = settings.getHeight();
		//创建图片缓冲器
		BufferedImage bufImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
		//创建2d图形引擎
		Graphics2D g2d = bufImg.createGraphics();
		
		//fillRect(int x,int y,int width,int height)：是用预定的颜色填充一个矩形，得到一个着色的矩形块。
		g2d.fillRect(0, 0, width, height);
		
		drawBorder(g2d, settings);
		drawPuzzleLines(g2d, settings);

		String codes = RandomStringUtils.randomAlphanumeric(settings.getCodeLength()).toUpperCase();
		drawCodes(g2d, settings, codes);
		CaptchaResult result = new CaptchaResult(codes);
		
		ByteArrayOutputStream bos = new ByteArrayOutputStream(128);
		FileUtils.writeToStream(bufImg, settings.getImageFormatName(), bos);
		result.setData(bos.toByteArray());
		
		return result;
	}

}