如何在Java中创建动画gif? [英] How can I create animated gif in Java?

查看:169
本文介绍了如何在Java中创建动画gif?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从BufferedImages集创建一个gif图像。我怎样才能做到这一点?纯Java中是否有这样的库(ImageMagick不是一个选项)?我找到了Gif4J库,但它不是免费的。

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'类允许你加载gif动画。我用'getResource()'加载图像。为此,我通常使用URL类来传递文件路径。在名称URL可能建议的远程机器中不需要该路径。

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

路径将是类文件夹中gif的路径。

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

参考文献:
http://docs.oracle.com/javase/tutorial/uiswing/components/icon.html#getresource

这篇关于如何在Java中创建动画gif?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆