android 高效顯示Bitmap - 開發文檔翻譯

由於本人英文能力實在有限,不足之初敬請諒解

本博客只要沒有註明“轉”,那麼均爲原創,轉貼請註明本博客鏈接鏈接

 

Displaying Bitmaps Efficiently

高效顯示Bitmap

 

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.

學習如何使用常規技術來處理和加載Bitmap對象,在一定程度上可以保持你的UI組件響應性以及避免超過應用內存限制。

如果你不小心,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,並且解釋如何處理併發問題

 

Caching Bitmaps

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響應性和流暢度

 

Managing Bitmap Memory

This lesson explains how to manage bitmap memory to maximize your app's performance.

這一節解釋如何管理bitmap內存來最大化你應用的性能

 

Displaying Bitmaps in Your UI

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地址

http://su1216.iteye.com/

http://blog.csdn.net/su1216/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章