title: Java gif frame to BufferedImage without holding all of them as an array
body: <p>So I've tried a number of times, and I just can't get it to work. I have a program out there that converts animated GIFs into a sequence of PNGs with a bunch of configurable settings. </p>
  
  <p>The problem is, the only ways I could find to be able to read frames of the GIF as BufferedImages and reuse the ImageReader involved making an array or some type of list that stores all the frames. This is very convenient, but for long, high resolution files, this eats up a lot of ram. Ideally I'd like to read them one at a time, and dispose of them when I am done with the frame. I have tried to study how compressed GIFs work, but the way disposal works is proving to be a bit over my head. The two essential methods I have tried and failed miserably to code are </p>
  
  <pre><code>public BufferedImage getNextFrame() 
  </code></pre>
  
  <p>to return the uncompressed, full next frame, and </p>
  
  <pre><code>public void reset()
  </code></pre>
  
  <p>to reset the index at 0. I have realized it is impossible to efficiently jump to an arbitrary frame without storing every one as an index of an array or list. </p>
  
  <p>Can someone give me some pointers on how to manage GIFs in a resource efficient way when I intend to do more with the frames than simply display them? I'm not asking you to write the entire thing, but just give me an idea of how one would do this. </p>