Has anybody managed to convince ImageIO to write an animated GIF, and in particular setting the correct metadata? My first attempt is roughly as follows (where b1 and b2 are BufferedImages):
ImageTypeSpecifier spec = new ImageTypeSpecifier(b1); ImageWriter wr = ImageIO.getImageWriters(spec, "GIF").next(); wr.setOutput(ImageIO.createImageOutputStream(new File("C:\\Flashing.gif"))); ImageWriteParam param = wr.getDefaultWriteParam(); IIOMetadata meta = wr.getDefaultImageMetadata(spec, param); wr.prepareWriteSequence(meta); wr.writeToSequence(new IIOImage(b1, null, null), param); wr.writeToSequence(new IIOImage(b2, null, null), param);
This appears to almost work, but:
If anyone has got writing animated GIFs from ImageIO to work and can share a snippet of working code or how to fix the above problems, it would be greatly appreciated!
I ran across this question, and decided to try it out; It took a small but non-trivial amount create a usable class (thanks ax) -- so I thought I might share the code around: here is a small class for creating an animated gif image from a number of other images. Archived version
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With