Thursday, December 13, 2007

Creating an image file (jpg) using java

You can create the custom images using java with the following snippet. This can be productively used in sign up forms to make the user enter the text in the image manually (to avoid automated script).
BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); 
 Graphics g = image.getGraphics(); 
 g.drawString("Hello World!!!", 10, 20); 
 try {  
   ImageIO.write(image, "jpg", new File("c:/CustomImage.jpg")); 
 } catch (IOException e) {  
  e.printStackTrace(); 
 }

1 comments:

Andy said...

Excellent - thank-you. It was exactly what I was looking for.