Displaying Bitmaps Efficiently
2016-07-06 10:13
357 查看
Learn how to use common techniques to process and load
your user interface (UI) components responsive and avoids exceeding your application memory limit. If you're not careful, bitmaps can quickly consume your available memory budget leading to an application crash due to the dreaded exception:
There are a number of reasons why loading bitmaps in your Android application is tricky:
Mobile devices typically have constrained system resources. Android devices can have as little as 16MB of memory available to a single application. The Android
Compatibility Definition Document(CDD), Section 3.7. Virtual Machine Compatibility gives the required minimum application memory for various screen sizes and densities. Applications should be optimized to perform under this minimum memory limit.
However, keep in mind many devices are configured with higher limits.
Bitmaps take up a lot of memory, especially for rich images like photographs. For example, the camera on the Galaxy
Nexus takes photos up to 2592x1936 pixels (5 megapixels). If the bitmap configuration used is
default from the Android 2.3 onward) then loading this image into memory takes about 19MB of memory (2592*1936*4 bytes), immediately exhausting the per-app limit on some devices.
Android app UI’s frequently require several bitmaps to be loaded at once. Components such as
include multiple bitmaps on-screen at once with many more potentially off-screen ready to show at the flick of a finger.
Loading Large Bitmaps EfficientlyThis lesson walks you through decoding large bitmaps without exceeding the per application memory limit.Processing Bitmaps Off the UI ThreadBitmap processing (resizing, downloading from a remote source, etc.) should never take place on the main UI thread. This lesson walks you through processing bitmaps in a background thread using
explains how to handle concurrency issues.Caching BitmapsThis lesson walks you through using a memory and disk bitmap cache to improve the responsiveness and fluidity of your UI when loading multiple bitmaps.Managing Bitmap MemoryThis lesson explains how to manage bitmap memory to maximize your app's performance.Displaying Bitmaps in Your UIThis lesson brings everything together, showing you how to load multiple bitmaps into components like
a background thread and bitmap cache.
Bitmapobjects in a way that keeps
your user interface (UI) components responsive and avoids exceeding your application memory limit. If you're not careful, bitmaps can quickly consume your available memory budget leading to an application crash due to the dreaded exception:
java.lang.OutofMemoryError: bitmap size exceeds VM budget.
There are a number of reasons why loading bitmaps in your Android application is tricky:
Mobile devices typically have constrained system resources. Android devices can have as little as 16MB of memory available to a single application. The Android
Compatibility Definition Document(CDD), Section 3.7. Virtual Machine Compatibility gives the required minimum application memory for various screen sizes and densities. Applications should be optimized to perform under this minimum memory limit.
However, keep in mind many devices are configured with higher limits.
Bitmaps take up a lot of memory, especially for rich images like photographs. For example, the camera on the Galaxy
Nexus takes photos up to 2592x1936 pixels (5 megapixels). If the bitmap configuration used is
ARGB_8888(the
default from the Android 2.3 onward) then loading this image into memory takes about 19MB of memory (2592*1936*4 bytes), immediately exhausting the per-app limit on some devices.
Android app UI’s frequently require several bitmaps to be loaded at once. Components such as
ListView,
GridViewand
ViewPagercommonly
include multiple bitmaps on-screen at once with many more potentially off-screen ready to show at the flick of a finger.
Lessons
Loading Large Bitmaps EfficientlyThis lesson walks you through decoding large bitmaps without exceeding the per application memory limit.Processing Bitmaps Off the UI ThreadBitmap processing (resizing, downloading from a remote source, etc.) should never take place on the main UI thread. This lesson walks you through processing bitmaps in a background thread using AsyncTaskand
explains how to handle concurrency issues.Caching BitmapsThis lesson walks you through using a memory and disk bitmap cache to improve the responsiveness and fluidity of your UI when loading multiple bitmaps.Managing Bitmap MemoryThis lesson explains how to manage bitmap memory to maximize your app's performance.Displaying Bitmaps in Your UIThis lesson brings everything together, showing you how to load multiple bitmaps into components like
ViewPagerand
GridViewusing
a background thread and bitmap cache.
相关文章推荐
- 使用jdbc修改并显示数据库中的数据
- 小米2系列机器在ubuntu系统里adb devices找不到设备的解决方法
- Ehcache学习总结(3)--Ehcache 整合Spring 使用页面、对象缓存
- Ehcache学习总结(3)--Ehcache 整合Spring 使用页面、对象缓存
- Apache ActiveMQ实战(1)-基本安装配置与消息类型
- Git解决分支冲突及分支管理策略
- Apache ActiveMQ实战(1)-基本安装配置与消息类型
- 移动端页面总结
- MFC界面库BCGControlBar v25.0新功能详解二:网格和报表控件
- DialogFragment使用细节
- Xamarin提示Build-tools版本过老
- IOS代码笔记UIView的placeholder的效果
- media的两张图,以前画的
- MyBatis持久层框架的用法知识小结
- 小谈如何解决VC6.0 open崩溃的问题(已解决)
- Ajax笔记
- JDK JRE JVM的区别:
- python 线程简单使用----1利用threading 实现多线程
- 转python调用Go代码
- Swift - UIView,UILabel,UIButton,UIImageView