This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
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.