【发布时间】:2021-06-19 12:56:20
【问题描述】:
我尝试了很多方法将 gif 文件转换为动画 webp 文件,但都不起作用。
我首先从 webp/png 文件中创建了一个 gif 并将其加载到文件中以将其保存为 webp:
//Bitmap from png / webp
Bitmap bmpAnimGif = BitmapFactory.decodeFile(String.valueOf(file));
//Converting it into gif
ByteArrayOutputStream bos = new ByteArrayOutputStream();
AnimatedGifEncoder encoder = new AnimatedGifEncoder();
encoder.start(bos);
encoder.addFrame(bmpAnimGif);
encoder.finish();
byte[] array = bos.toByteArray();
// Save to file (gif)
File output = new File(StickerPackActivity.BASE_PATH + "/" + "temp_animated.gif");
FileOutputStream fos = new FileOutputStream(output);
fos.write(array);
fos.close();
//load gif and saved it as webp
File output2 = new File(StickerPackActivity.BASE_PATH + "/" + "temp_animatedwebp.webp");
fOut = new FileOutputStream(output2);
compressImage(BitmapFactory.decodeFile(String.valueOf(output)), false).compress(Bitmap.CompressFormat.WEBP_LOSSY, 80, fOut);
fOut.flush();
fOut.close();
我猜最后一步是错误的... 如果你能帮我解决我的问题就好了。
【问题讨论】:
标签: android gif converters webp