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

本文深入探讨了Android应用中位图加载的挑战及解决方案,着重讲解了如何通过常见技术优化内存使用,确保UI组件响应并避免应用内存溢出。详细分析了移动设备受限的系统资源、内存预算限制、位图占用内存特性及其对应用性能的影响,并提供了实用建议以优化内存管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

英文不是很好,但是还是想强迫自己去阅读英文文档,毕竟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 这样的控件经常一次包含多个位图在视线里还有视线外更多可能准备随着手指的弹出
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值