4

I am compressing an image in the WEBP-format with the following code:

bitmap.compress(Bitmap.CompressFormat.WEBP, 100, outputStream)

Although I am using highest quality-settings, it looks like the image is not compressed lossless but lossy. Corresponding to the Android developer docs, it should be possible to compress WEBP-files lossless: http://developer.android.com/guide/appendix/media-formats.html http://developer.android.com/reference/android/graphics/Bitmap.CompressFormat.html

I am doing this on a Nexus 4 with Android 4.4.2 Kitkat. Furthermore I am using the highest SDK throughout in my project.

Has anyone got an idea, how to save bitmaps as lossless WEBP-images?

Alex
  • 569
  • 5
  • 21
  • I haven't used WEBP, but is there a way you can use some other utilities (e.g., ImageMagick) to confirm, conclusively, that the image is being saved lossy rather than lossless? If I were a betting man, I'd guess that you are right and the media formats page is wrong, where there is no direct means to encode in WEBP in a lossless fashion. But, if I were in your shoes, I'd want to know for certain whether the image is being saved lossy or not. – CommonsWare Apr 06 '14 at 17:57
  • @CommonsWare I am loading the image again in my application and there it can be seen that the pixels are not the same as the pixels before. If I do the same thing with PNG as compression algorithm it works fine, which means that I get exactly the same picture again. I am using exactly the same algorithm I am just changing from PNG to WEBP. – Alex Apr 06 '14 at 18:05
  • @CommonsWare ...furthermore many pixels have the same value after saving the image as WEBP which kind of indicates a lossy compression. – Alex Apr 06 '14 at 18:12

1 Answers1

0

As of Build.VERSION_CODES.Q, a value of 100 results in a file in the lossless WEBP format. Otherwise the file will be in the lossy WEBP format.

https://developer.android.com/reference/android/graphics/Bitmap.CompressFormat#WEBP

It seems lossless WebP compression is only available for devices with at least Android Q, by specifying WEBP_LOSSLESS as the compression format (or WEBP with quality 100).

Pat Lee
  • 1,567
  • 1
  • 9
  • 13