4

I'm android developer from Korea

My project has features about loading large amount of huge bitmap (about 2,000 x 1,500px)

I had a some experiments to compare time complexity and space complexity between Asset and Drawable

By result, Asset is better than drawable in space complexity.

When I load huge images using drawable, my app broken down with OutOfMemoryException : the bitmap size exceeds VM budget

but when I load huge images using Asset, It works fine!

Anybody know reason why this happened?

or Anybody know about how Drawable works in Android framework? step-by-step.

Please help.

Thank you for reading.

Jindong Jung
  • 457
  • 1
  • 6
  • 19
  • I'm not sure but it could be because when getting stuff from the assets you manage directly the streams (be it image, sound or anithing else) while whe using Drawable android tries to get an image that can have a maximum height and width. – Ayoub Feb 04 '14 at 07:25
  • I think [Android: Accessing images from assets/drawable folders][1] you will get the answer. [1]: http://stackoverflow.com/a/8400282/1839336 – GrIsHu Feb 04 '14 at 07:30

1 Answers1

6

If you are passing an asset Uri to something like an ImageView, the framework will use BitmapFactory to stream a downsampled version of the image from disk. This is the technique it uses under the hood.

Drawables do not use this technique, for performance reasons. It is not generally expected that huge images are stored as Drawables, and Drawable loading happens many times over your app's lifecycle, so they are streamed from disk in their entirety and cached in memory.

tad
  • 1,383
  • 11
  • 16