File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Generating images Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Generating images" Watch "Generating images" New topic

Generating images

pradeep selvaraj
Ranch Hand

Joined: Nov 29, 2005
Posts: 62
How could i generate images in memory and save them into a image(any image format) file.


[<a href="" target="_blank" rel="nofollow">CyVis - Software Complexity Visualiser</a>] [<a href="" target="_blank" rel="nofollow">Pradeep's Blog</a>]
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

The easiest way to do this is use the new ImageIO API - the last sample on this page shows how easy it is to read and write images in many formats using it. The only problem is that ImageIO does not support writing GIF files "out of the box" currently - however, there are plugins you can use to do so, and GIF encoding will be included in the next JDK release (since the GIF patent will have expired).

The "in memory" part would be accomplished by using the BufferedImage class. You create one (or load one using ImageIO), call getGraphics() or createGraphics() on it to get the graphics context, and then just draw on it the same way you would draw on an AWT component in it's paint() method or a Swing component in it's paintComponent() method.

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
I agree. Here's the link:
subject: Generating images
It's not a secret anymore!