int numberOfFrames = getNumberOfFrames();
BufferedImage frame = null;
currFrameIndex = 0;
if (frameSize.getHeight() > 0.0 && frameSize.getWidth() > 0.0
&& numberOfFrames > 0) {
AnimatedGifEncoder encoder = new AnimatedGifEncoder();
encoder.start(output);
encoder.setRepeat(getRepeat());
int[] delays = getFrameDelays();
ImageRenderer renderer = (ImageRenderer) getRenderer(null);
while (currFrameIndex < numberOfFrames) {
frame = renderer.createImage(frameSize.width,
frameSize.height);
Graphics2D graphics = frame.createGraphics();
paint(context, graphics, currFrameIndex++);
graphics.dispose();
encoder.addFrame(frame);
if (delays != null && delays.length > currFrameIndex) {
encoder.setDelay(delays[currFrameIndex]);
}
}
encoder.finish();
}
output.flush();
output.close();
} catch (IOException e) {
// TODO Auto-generated catch block