Лучший способ - сгенерировать BufferedImage
:
BufferedImage img = new BufferedImage(int width, int height, int imageType)
// you can find the Types variables in the api
Затем, сгенерировав Graphics2D этого изображения, этот объект позволяет установить фон и нарисовать фигуры:
Graphics2D g = img.createGraphics();
g.setBackground(Color color) ; //Find how to built this object look at the java api
g.draw(Shape s);
g.dispose(); //don't forget it!!!
Для построения изображения:
File file = new File(dir, name);
try{
ImageIO.write(img, "gif", file);
}catch(IOException e){
e.printStackTrace();
}