Android Drawable vs Asset in Image loading performance

旧巷老猫 提交于 2019-12-07 07:11:35

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/21545900/android-drawable-vs-asset-in-image-loading-performance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!