现在的位置: 首页 > 综合 > 正文

用JAVA生成GIF动画

2013年08月01日 ⁄ 综合 ⁄ 共 534字 ⁄ 字号 评论关闭

下面的网站提供了一个免费的非常好用的GIF动画处理的源码:http://www.fmsware.com/stuff/gif.html

使用起来非常简单:

* 分解GIF:
 *    GifDecoder d = new GifDecoder();
 *    d.read("sample.gif");
 *    int n = d.getFrameCount();
 *    for (int i = 0; i < n; i++) {
 *       BufferedImage frame = d.getFrame(i);  // frame i
 *       int t = d.getDelay(i);  // display duration of frame in milliseconds
 *       // do something with frame
 *    }

 * 合成GIF:
 *    AnimatedGifEncoder e = new AnimatedGifEncoder();
 *    e.start(outputFileName);
 *    e.setDelay(1000);   // 1 frame per sec
 *    e.addFrame(image1);
 *    e.addFrame(image2);
 *    e.finish();

抱歉!评论已关闭.