在Android中,位图是否可以转换或保存为webp格式?
我搜索了一下,但是没有找到什么有用的信息。
我需要将图像保存为webp格式,否则需要先保存为PNG/JPEG,然后通过编程方式转换为webp。
CompressFormat.WEBP
将任何位图编码为WEBP格式。FileOutputStream out = new FileOutputStream(path);
bitmap.compress(Bitmap.CompressFormat.WEBP, 100, out);
out.close();
FileOutputStream(file).use { out ->
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
bmp.compress(
Bitmap.CompressFormat.WEBP_LOSSLESS, // or WEBP_LOSSY
100,out)
} else {
bmp.compress(Bitmap.CompressFormat.WEBP,100,out)
}
}