16

I would like to create a gif image from the set of BufferedImages. How can I do this? Is there such library in pure Java (ImageMagick is not an option)? I've found Gif4J library but it's not royality-free.

MaXal
  • 841
  • 2
  • 8
  • 23
  • 2
    Try this [gif encoder](http://www.java2s.com/Code/Java/2D-Graphics-GUI/AnimatedGifEncoder.htm). **Related Question:** - [Creating Animated-gif with imageio](http://stackoverflow.com/questions/777947/creating-animated-gif-with-imageio) – Emil Mar 18 '11 at 08:59
  • There is also this http://elliot.kroo.net/software/java/GifSequenceWriter/ which seems to work well. – Oliver Coleman May 01 '14 at 06:47
  • [This](https://github.com/dragon66/icafe) link and the wiki examples there will do what you want. You can control the frame rate as well. It's pure Java. You may not even need to use imageio! – dragon66 Sep 19 '14 at 19:47 – dragon66 Oct 28 '15 at 20:04
  • And [this](https://github.com/dragon66/animated-gif-writer) easy to use standalone AnimatedGIFWriter. – dragon66 Nov 02 '15 at 22:01

2 Answers2

2

I just answer a similar question here, but I think that my solution can help.

'ImageIcon' class allows you to load gif animations. I load the image with 'getResource()'. For doing this I normally us URL class to pass the file path. The path does not need to be necessary in a remote machine as the name URL may suggest.

URL url = This.class.getResource(path);
Icon myImgIcon = new ImageIcon(url);
JLabel imageLbl = new JLabel(myImgIcon);
component.add(imageLbl, BorderLayout.CENTER);

path will be the path of the gif inside of the class folder.

References: http://docs.oracle.com/javase/tutorial/uiswing/components/icon.html#getresource

Community
  • 1
  • 1
Antonio
  • 851
  • 2
  • 8
  • 17
0

There is an image processing library, akin to Picasso which uses the very same AnimatedGifEncoder class mentioned by Lifelogger- Glide Docs, Glide

 AnimatedGifEncoder e = new AnimatedGifEncoder();
 e.start(outputFileName);
 e.setDelay(1000);   // 1 frame per sec
 e.addFrame(image1);
 e.addFrame(image2);
 e.finish();
Nevermore
  • 7,141
  • 5
  • 42
  • 64