因为本人英文能力实在有限,不足之初敬请谅解html
本博客只要没有注明“转”,那么均为原创,转贴请注明本博客连接连接java
Displaying Bitmaps Efficientlyandroid
高效显示Bitmapapi
Learn how to use common techniques to process and load Bitmap objects 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.app
学习如何使用常规技术来处理和加载Bitmap对象,在必定程度上能够保持你的UI组件响应性以及避免超过应用内存限制。less
若是你不当心,bitmap能很快消费光你的可用内存,因为下面可怕的异常致使应用崩溃性能
java.lang.OutofMemoryError: bitmap size exceeds VM budget.学习
There are a number of reasons why loading bitmaps in your Android application is tricky:
一些缘由是为何在你的android应用里加载bitmap是须要技巧的:
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.
移动设备每每资源系统有限
android设备对一个应用来讲至少有16MB的可用内存。
Android Compatibility Definition Document (CDD),章节3.7,Virtual Machine Compatibility
应用在这种最小内存限制下,应该最优化的被执行
然而,有不少设备配置了更高的限制
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.
Bitmap占用大量内存,尤为是像照片一类色彩丰富的图片
例如:Galaxy Nexus上面的相机拍出的照片须要2592x1936像素(5 megapixels).
若是bitmap使用ARGB_8888作配置(android2.3以前的默认配置),那么加载这张图片到内存中大概须要19MB(2592*1936*4 bytes),在一些设备上,立刻就耗尽了单个app限制
Android app UI’s frequently require several bitmaps to be loaded at once.
Components such as ListView, GridView and ViewPager commonly include multiple bitmaps on-screen at once with many more potentially off-screen ready to show at the flick of a finger.
android应用UI频繁的须要一次同时加载多张图片
像ListView,ridView 和 ViewPager这样的组件,一般一次同时含有多张图片在屏幕上,还有不少在屏幕外准备当手指滑动时显示的图片
(下面提到了5篇文章已经翻译完,连接直接链到我翻译后的文章)
Lessons
Loading Large Bitmaps Efficiently
This lesson walks you through decoding large bitmaps without exceeding the per application memory limit.
这节教你如何不超出单个应用内存限制解码大图片
Processing Bitmaps Off the UI Thread
Bitmap 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 AsyncTask and explains how to handle concurrency issues.
bitmap处理(缩放、从远程下载等)毫不应该在主线程中发生
这一节教你使用AsyncTask如何在后台线程处理bitmap,而且解释如何处理并发问题
This lesson walks you through using a memory and disk bitmap cache to improve the responsiveness and fluidity of your UI when loading multiple bitmaps.
这一节教你当加载多bitmap时,使用内存bitmap缓存和磁盘bitmap缓存来改进你你的UI响应性和流畅度
This lesson explains how to manage bitmap memory to maximize your app's performance.
这一节解释如何管理bitmap内存来最大化你应用的性能
This lesson brings everything together, showing you how to load multiple bitmaps into components like ViewPager and GridView using a background thread and bitmap cache.
这节把全部事情放到一块儿,展现如何使用后台线程和bitmap缓存加载多图片到ViewPager 和 GridView组件中
原文地址以下,英文水平实在有限,但愿拍砖同时能给予指正。
http://developer.android.com/training/displaying-bitmaps/index.html
转贴请保留如下连接
本人blog地址