title: Writing an animated gif from BufferedImages
body: <p>I have a program that loads a spritesheet, creates BufferedImages of each frame on the sheet, and writes it to an animated gif. Using the class provided by Elliot Kroo on <a href="https://stackoverflow.com/questions/777947/creating-animated-gif-with-imageio">Creating animated GIF with ImageIO?</a>, I was able to successfully output a file. However, the gif doesn't animate quite right. The sheet I provided was a .png with a transparent background, so every subsequent frame is just put on top of the last frames, with differences showing through the transparent background (<a href="http://i55.tinypic.com/2qvawdx.gif" rel="nofollow noreferrer">Example</a>). Here's the code that uses the gif writer:  </p>
  
  <pre><code>ImageOutputStream output = new FileImageOutputStream(new File(savePath));
  GifSequenceWriter writer = new GifSequenceWriter(output, data[0].getType(), delay, true);
  for(BufferedImage bi:data)
  {
      writer.writeToSequence(bi);
  }
  writer.close();
  output.close();
  </code></pre>
  
  <p>Where data is an array of each frame as a BufferedImage (which I have also checked, and don't seem to be the problem). Is this a limitation of .gifs or the Java ImageWriters? Or can I edit a setting somewhere to prevent this? I'd rather not put a background if I don't have to.</p>