19

Background

Android P presents a new API for loading images, using ImageDecoder class.

The problem

Not much is documented about this class, so I'm just curious about its usage, and whether I should consider using it when possible, instead of Glide library, for example, which Google itself recommends on using:

For most cases, we recommend that you use the Glide library to fetch, decode, and display bitmaps in your app. Glide abstracts out most of the complexity in handling these and other tasks related to working with bitmaps and other images on Android. For information about using and downloading Glide, visit the Glide repository on GitHub.

What I've found

I've found some articles about it, giving clues of what it can do and how to use it:

However, according to my tests, loading a GIF animation is worse using this API (takes more memory, uses about the same CPU) compared to Movie class, which in itself is worse than third party libraries such as android-gif-drawable . What I've tested is a rather long GIF animation. On the third party library it took about 59MB. Using Movie class it took about 168MB, and using the new ImageDecoder API it took 200-300MB ...

So in short, what I've found about this API, is that:

  1. It's supposed to replace BitmapFactory
  2. It supports loading animated GIF/WEBP
  3. It has some listeners for pre/post processing
  4. It's supposed to be more efficient, but I don't see it, at least not in terms of memory usage.

The questions

  1. Are there any advantages of using this API, over what we already have in third party libraries ? Meaning Glide for static images, and "android-gif-drawable" for GIF (and maybe something for WEBP that I didn't search) ?

  2. Does it perform better behind the scenes, and I shouldn't care about its memory usage?

  3. Does it have a memory/disk cache? If so, how does it manage its memory cache now that Android doesn't store Bitmaps in the heap memory (wrote about it here) ?

  4. Is it possible this API will be available in the support library? Otherwise I don't see much need to use it at all... EDIT: seems it might be on the support library. Link here.

android developer
  • 114,585
  • 152
  • 739
  • 1,270
  • 2
    "Does it have a memory/disk cache?" -- no. "Is it possible this API will be available in the support library?" -- I will be somewhat surprised if this happens. The support library to date has been pure Java (and, perhaps in the future, Kotlin), while `ImageDecoder` probably uses native code (C/C++). – CommonsWare Apr 30 '18 at 16:46
  • @CommonsWare Is it more efficient in some way, though? I know that in terms of memory it's even worse than Movie class (let alone the library I've found), but maybe in other terms it's better? Also, Doesn't Movie class also use C/C++ (native code) already? – android developer Apr 30 '18 at 16:48
  • "Is it more efficient in some way, though?" -- I have no idea, sorry. "Doesn't Movie class also use C/C++ (native code) already?" -- probably. I haven't looked. My point regarding native code was only in respect to your comment regarding a backport being put in the support library. – CommonsWare Apr 30 '18 at 16:52
  • @CommonsWare So what's the point in having this... I don't see currently any reason in using it, unless perhaps it has better performance or that it looks smoother (it was said in some place that the animation is used on a special thread for it). – android developer Apr 30 '18 at 17:09
  • "what's the point in having this" -- other than the animation support, I have no idea. It baffled me too when it was released. – CommonsWare Apr 30 '18 at 17:14
  • @CommonsWare Have you written about this on your blog? – android developer Apr 30 '18 at 17:35
  • Other than mentioning its existence, no, because I don't know what to write about. – CommonsWare Apr 30 '18 at 17:54
  • @CommonsWare OK thank you. I hope things will get clear when P is final. – android developer Apr 30 '18 at 18:31
  • 2
    It looks like Google is planning to add it in support library : https://issuetracker.google.com/issues/78041382 – Galeen Jul 27 '18 at 05:17

0 Answers0