Monday, January 14, 2008

Technical: Output Java3D as Image

We initially thought that Java3D can only be displayed on a browser thru a Java Applet. This worries us as mobile browsers DON'T support it. After a long long long period of research, we finally found a way to output the Java3D result as an image file. 

We can save a BufferImage object using write method of the ImageIO class. Firstly, we import the necessary class,
import javax.imageio.ImageIO;

The write method is like this:

public static boolean write(RenderedImage im, 
String formatName,
File output)
  throws IOException

As you can see, im is the RenderedImage to be written, formatName is the String which tells us the format (i.e png or jpg) and output is the file object to be written to. An example usage of the method for PNG file format shown below:

ImageIO.write(captchaImage, "png", file);



The image below shows the resultant jpg image. Now will pass this portion of code to Alan, for him to try on his Captcha 3D text and also try to produce this image by invoking a Java Servlet. 

No comments:

Post a Comment