Android ImageView setImageBitmap

萝らか妹 提交于 2019-12-12 21:42:35

问题


I'm trying to better understand how Android handle images in order to use memory more efficiently. I have an image stored in the Bitmap and I'm using ImageView.setImageBitmap() to display it. Now the question is - will it use the Bitmap I've passed it in the future, or it's making a copy of it and the Bitmap I've created isn't used anymore after the call to setImageBitmap?

Asuming it's gonna keep reference to the Bitmap I've passed, how is it gonna behave when Bitmap was created via BitmapFactory using inPurgeable option? Will ImageView prevent the Bitmap from being temporarily purged from the memory? Is it gonna happen only when ImageView has View.VISIBLE state, or also when View.GONE and View.INVISIBLE? Or maybe only while ImageView is visible on the screen?

And one more thing - looking through Android source code reveals that encoded byte data is always copied into memory (inInputShareable is currently ignored). Is it counted towards the 16/24MB memory limit for android Java application?

Thanks


回答1:


Take a look at this article : http://developer.android.com/training/displaying-bitmaps/index.html

There's some useful lessons that helps you to understand android's memory management better



来源:https://stackoverflow.com/questions/7938785/android-imageview-setimagebitmap

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