Can bitmap be converted or saved to the webp format in android?
I search out for that but it turns out to be a dead end for me.
I need to save image to webp formate or else need to save in PNG/JPEG then convert to webp programmatically.
You can use CompressFormat.WEBP
to encode any bitmap in WEBP format.
Example:
FileOutputStream out = new FileOutputStream(path);
bitmap.compress(Bitmap.CompressFormat.WEBP, 100, out);
out.close();
Since Bitmap.CompressFormat.WEBP is deprecated in Android 30, use as below
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)
}
}