直接用哔哩哔哩弄的一个库,传送门:https://github.com/bilibili/BurstLinker
他那个库的文档写的比较简陋,所以我决定,我也写得十分简陋
引用:
api 'com.bilibili:burst-linker:0.0.13'
使用:
/**
* @param imgList 输入的图片路径列表
* @param outputPath 输出路径,/xxx/xxx.gif
* @param width 生成的gif的宽,单位像素
* @param height 生成的gif的高,单位像素
* @param time 每张图片的间隔时间,单位毫秒
*/
public static void createGif(List<String> imgList, String outputPath, int width, int height, int time) {
ALog.e("git宽高:{}x{};切换时间:{}", width, height, time);
BurstLinker burstLinker = new BurstLinker();
try {
burstLinker.init(width, height, outputPath);
for (String imgPath : imgList) {
//这个量化跟抖动参数,老实说我也不明白是啥意思
burstLinker.connect(BitmapFactory.decodeFile(imgPath),
BurstLinker.OCTREE_QUANTIZER,
BurstLinker.NO_DITHER,
time
);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
burstLinker.release();
}
}