java试用静态图片制作gif
参考博客:https://www.cnblogs.com/dreammyle/p/4843365.html
代码中需要的依赖:
<!-- gif --><dependency>
<groupId>com.madgag</groupId>
<artifactId>animated-gif-lib</artifactId>
<version>1.4</version>
</dependency>
代码:
import java.awt.image.BufferedImage;import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import com.madgag.gif.fmsware.AnimatedGifEncoder;
public class GifDemo {
public static void main(String[] args) {
try {
AnimatedGifEncoder e = new AnimatedGifEncoder();
e.setRepeat(0);
e.start("d:/tmp/test1.gif");
String pic[] = new String[] {
"d:\\Pictures\\1.jpg",
"d:\\Pictures\\2.jpg",
"d:\\Pictures\\6.jpg",
"d:\\Pictures\\8.jpg"};
BufferedImage src[] = new BufferedImage[pic.length];
for (int i = 0; i < src.length; i++) {
e.setDelay(200); //设置播放的延迟时间
src[i] = ImageIO.read(new File(pic[i])); // 读入需要播放的jpg文件
e.addFrame(src[i]); //添加到帧中
}
e.finish();
} catch (IOException e) {
e.printStackTrace();
}
}
}
得到的图片使用浏览器预览,这个播放时间比较快,查一查这个类是否控制时间等设置
以上是 java试用静态图片制作gif 的全部内容, 来源链接: utcz.com/z/391399.html