1

i'm making some experiments with the relatively new webP image format , that is supported on android 4 (ICS) as shown here .

so far , in order to get the image size before loading it , i used the next code (similar to what google shows here) :

final BitmapFactory.Options options=new BitmapFactory.Options();
options.inJustDecodeBounds=true;
BitmapFactory.decodeStream(inputStream,null,options);
//image size is in options.outWidth,options.outHeight 

however , when i use it on a webP image that has transparency , it seems that it can't get this info at all (returns -1 for both width and height) .

is it possible that google has a bug on decoding this image file type ?

is there a way to overcome this?

in order to test it , just convert a png file that has transparency (like this one that i've used and added some transparent pixels via paint.net app ) to a webP format (using google's tool ), and try to read the resolution of the file like the code i've used.

halfer
  • 19,824
  • 17
  • 99
  • 186
android developer
  • 114,585
  • 152
  • 739
  • 1,270

1 Answers1

0

I ran into this issue as well.

Sadly, according to this bug report support for WEBP with transparency was only added in Android JB-MR2 (4.2).

So in android 4.0 until 4.2 WEBP only works if there's no alpha channel.

Joachim
  • 901
  • 8
  • 18
  • do you know of a library that can decode&encode webP files? that would be great and remove the need for android version compatibility . – android developer Jun 04 '13 at 10:06
  • As far as I know there's only the native route. Explained in [this answer](http://stackoverflow.com/a/8422707/970993). But I think you cannot use for example Bitmap options like inJustDecodeBounds then. Personally I'm just serving webp to android 4.2+, which will be a growing target anyway. But a support library for this would be great. – Joachim Jun 04 '13 at 12:58
  • looks like a lot of work , and that's only for simple decoding, after you got the whole byte array. it might also not be efficient as you need to load the entire byte array before decoding. – android developer Jun 04 '13 at 13:02