1

This question is in reference to the following SO response.

Convert each animated GIF frame to a separate BufferedImage

This chuck of code worked great for loading GIFs into my program in way such that I could use them inside an existing framework I'm using. i.e. Loading them as a list of BufferedImages while reading each frames "delay" worked great for me! However, it doesn't seam to preserve the transparent pixels in the source GIF file. I don't understand how exactly the metadata is retrieved in the above code, and where to look for transparent pixels in the underlying data.

So as the title says, I need to load the GIF, in a similar manner to the above code, but while preserving transparency. If someone knows a better or different way to simply load a GIF as a sequence of Images, that would be great to.

Community
  • 1
  • 1
Mathhead200
  • 331
  • 1
  • 3
  • 6
  • Have you tried http://stackoverflow.com/a/9754907/1759128 – ItachiUchiha Mar 04 '14 at 21:06
  • No I haven't, thanks! But am I hearing that trying to load a GIF into Java while preserving transparency is not worth the effort? I'm try to load them (the GIF images) to be used as animations in a sprite-based Game Library I've been working on for quite some time. Right now I either build the animation out of a bunch of BufferedImages, or load them via a sprite sheet. I've keep getting requests on how to load GIFs, but don't know much about image formats. – Mathhead200 Mar 04 '14 at 21:23
  • You can try this: Where ever the code in the linked answer sets the background color (like `g.setColor(backgroundColor);g.fillRect(...);`), you could instead set the alpha composite to the `CLEAR` rule (like `g.setComposite(AlphaComposite.Clear);g.fillRect(...)`) + remember to restore the composite to it's previous value afterwards, probably `AlphaComposite.SrcOver`. With this you will start with a transparent background, instead of the bg color. I'd post an answer, but the code is too long... ;-) – Harald K Mar 05 '14 at 17:29

0 Answers0