Android将gif转换为动画webp
我尝试了很多方法将gif文件转换为动画webp文件,但都不起作用 我首先从一个webp/png文件中创建了一个gif文件,并将其加载到一个文件中以另存为webp:Android将gif转换为动画webp,android,gif,converters,webp,Android,Gif,Converters,Webp,我尝试了很多方法将gif文件转换为动画webp文件,但都不起作用 我首先从一个webp/png文件中创建了一个gif文件,并将其加载到一个文件中以另存为webp: //Bitmap from png / webp Bitmap bmpAnimGif = BitmapFactory.decodeFile(String.valueOf(file)); //Converting it into gif ByteArrayOutputS
//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();
我想最后一步是错的。。。
如果您能帮我解决这个问题,那就太好了。要将动画Gif转换为动画WEBP,请使用:)快乐编码 例如:WebpIO.create().toWEBP(“hello.gif”、“hello.webp”)
我能够使用以下工具将gif转换为动画webp:
implementation 'com.arthenica:ffmpeg-kit-full:4.4.LTS'
FFmpegSession session = FFmpegKit.execute("-i input_path/input.gif -vcodec webp -loop 0 -pix_fmt yuv420p output_path/output.webp");
if (ReturnCode.isSuccess(session.getReturnCode())) {
tvFilePath.setText("success");
// SUCCESS
} else if (ReturnCode.isCancel(session.getReturnCode())) {
// CANCEL
} else {
// FAILURE
Log.d("ffmpeg", String.format("Command failed with state %s and rc %s.%s", session.getState(), session.getReturnCode(), session.getFailStackTrace()));
}