View Javadoc

1   /*
2    * JCaptcha, the open source java framework for captcha definition and integration
3    * Copyright (c)  2007 jcaptcha.net. All Rights Reserved.
4    * See the LICENSE.txt file distributed with this package.
5    */
6   
7   /*
8    * jcaptcha, the open source java framework for captcha definition and integration
9    * copyright (c)  2007 jcaptcha.net. All Rights Reserved.
10   * See the LICENSE.txt file distributed with this package.
11   */
12  
13  /*
14   * jcaptcha, the open source java framework for captcha definition and integration
15   * copyright (c)  2007 jcaptcha.net. All Rights Reserved.
16   * See the LICENSE.txt file distributed with this package.
17   */
18  
19  package com.octo.captcha.engine.image.utils;
20  
21  import com.octo.captcha.image.ImageCaptcha;
22  import com.octo.captcha.image.ImageCaptchaFactory;
23  import com.sun.image.codec.jpeg.ImageFormatException;
24  import com.sun.image.codec.jpeg.JPEGCodec;
25  import com.sun.image.codec.jpeg.JPEGImageEncoder;
26  
27  import java.awt.image.BufferedImage;
28  import java.io.File;
29  import java.io.FileOutputStream;
30  import java.io.IOException;
31  
32  /***
33   * <p>Description: </p>
34   *
35   * @author <a href="mailto:mga@octo.com">Mathieu Gandin</a>
36   * @version 1.0
37   */
38  public class SimpleImageCaptchaToJPEG {
39  
40      public static void main(String[] args)
41              throws ImageFormatException, IOException {
42  
43          com.octo.captcha.engine.image.gimpy.SimpleListImageCaptchaEngine bge =
44                  new com.octo.captcha.engine.image.gimpy.SimpleListImageCaptchaEngine();
45          System.out.println("got gimpy");
46  
47          ImageCaptchaFactory factory = bge.getImageCaptchaFactory();
48          System.out.println("got factory");
49  
50          ImageCaptcha pixCaptcha = factory.getImageCaptcha();
51          System.out.println("got image");
52  
53          System.out.println(pixCaptcha.getQuestion());
54  
55          BufferedImage bi = pixCaptcha.getImageChallenge();
56  
57          File f = new File("foo.jpg");
58  
59          JPEGImageEncoder jpegEncoder = JPEGCodec.createJPEGEncoder(
60                  new FileOutputStream(f));
61          jpegEncoder.encode(bi);
62      }
63  
64  }