开发者

How can I create animated gif in Java?

开发者 https://www.devze.com 2023-02-18 02:53 出处:网络
I would like to create a gif image from the set of BufferedImages. How can I do this? I开发者_开发技巧s there such library in pure Java (ImageMagick is not an option)? I\'ve found Gif4J library but it

I would like to create a gif image from the set of BufferedImages. How can I do this? I开发者_开发技巧s 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();
0

精彩评论

暂无评论...
验证码 换一张
取 消