如何在 Java 中创建动画 gif? [英] How can I create animated gif in Java?
问题描述
我想从一组 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);
path 将是类文件夹中 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屋!