简体   繁体   中英

How can I create animated gif in Java?

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.

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

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM