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(); 
 }

2 comments:

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

    ReplyDelete
  2. Great program with little extra customizations,
    Images can be created in java without any extra libs,
    http://www.javadomain.in/creating-image-using-java-without-extra-libs/

    ReplyDelete