栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

有没有一种方法可以用Java中的多个图像创建一个Gif图像?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

有没有一种方法可以用Java中的多个图像创建一个Gif图像?

这里有一个类的示例,该类从不同的图像创建动画的gif:

链接

编辑:链接似乎已死。 无论如何,为了清楚起见,这段代码是由Elliot Kroo完成的。

编辑2:感谢您

@Marco13
找到WayBackMachine链接。更新了参考!

该类提供以下方法:

class GifSequenceWriter {    public GifSequenceWriter(        ImageOutputStream outputStream,        int imageType,        int timeBetweenframesMS,        boolean loopContinuously);    public void writeToSequence(RenderedImage img);    public void close();}

还有一个小例子:

public static void main(String[] args) throws Exception {  if (args.length > 1) {    // grab the output image type from the first image in the sequence    BufferedImage firstImage = ImageIO.read(new File(args[0]));    // create a new BufferedOutputStream with the last argument    ImageOutputStream output =       new FileImageOutputStream(new File(args[args.length - 1]));    // create a gif sequence with the type of the first image, 1 second    // between frames, which loops continuously    GifSequenceWriter writer =       new GifSequenceWriter(output, firstImage.getType(), 1, false);    // write out the first image to our sequence...    writer.writeToSequence(firstImage);    for(int i=1; i<args.length-1; i++) {      BufferedImage nextImage = ImageIO.read(new File(args[i]));      writer.writeToSequence(nextImage);    }    writer.close();    output.close();  } else {    System.out.println(      "Usage: java GifSequenceWriter [list of gif files] [output file]");  }}

向Elliot Kroo推荐此代码。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/437868.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号