java处理GIF动态图规格,亲测可用
public static void main(String[] args) throws IOException {
//分解GIF:
GifDecoder d = new GifDecoder();
d.read("E:\\144_d9ea5c18-2a69-49cb-a4ed-90e514275c50.gif");
//获取gif图帧数
int n = d.getFrameCount();
//获取第一帧持续时间
int delay = d.getDelay(0);
// 合成GIF:
AnimatedGifEncoder e = new AnimatedGifEncoder();
//设置输出文件
e.start("E:\\qweqwe.gif");
//设置每一帧持续时间
e.setDelay(delay);
for (int i = 0; i < n; i++) {
BufferedImage frame = d.getFrame(i);
//处理每一帧图片的规格
BufferedImage bufferedImage = Thumbnails.of(frame).forceSize(1000, 1000).asBufferedImage();
//将处理好规格的流放进合成GIF对象中
e.addFrame(bufferedImage);
}
e.finish();
}