1Displaying Bitmaps Efficiently (位图有效显示)

来源:互联网 发布:传神翻译软件 编辑:程序博客网 时间:2024/05/29 00:30

英文不是很好,但是还是想强迫自己去阅读英文文档,毕竟android是外国人弄的。。。

翻译全凭词典,肯定很水,翻译不对的地方欢迎留言


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.

学习如何使用常见技术处理和加载位图方式保持你使用UI控件响应和避免应用内存溢出。

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:

这是一些理由为什么你的android应用加载位图是棘手的:


· Mobile devices typically have constrained system resources.

· 移动设备通常会限制系统资源。

Android devices can have as little as 16MB of memory available to a single application.

android设备提供给一个应用少于16MB的可用内存。

The Android Compatibility Definition Document (CDD), Section 3.7. 

android兼容解释文档(CDD),3.7节。

Virtual Machine Compatibility gives the required minimum application memory for various screen sizes and densities.

虚拟机通常提供应用所需的最小内存在不同屏幕大小和密度。

屏幕大小屏幕尺寸应用内存  small / nomal / large  ldpi / mdpi  16MB  small / nomal / large  tvdpi / hdpi  32MB  small / nomal / large  xhdpi  64MB  xlarge  mdpi  32MB  xlarge  tvdpi / hdpi  64MB  xlarge  xhdpi  128MB
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).

位图占用许多内存,尤其是类似照片这样的大量图像。例如用Galaxy Nexus拍摄2592X1936像素(5百万像素)照片。

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.

如果位图使用ARGB_8888(Android2.3后默认)配置用内存加载这个图像要大约花费19MB的内存(2592*1936*4 bytes),立即突破每个应用的限制在一些设备上。

  • 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,gridview,viewpager 这样的控件经常一次包含多个位图在视线里还有视线外更多可能准备随着手指的弹出