處理點陣圖
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
試用 Compose
Jetpack Compose 是 Android 推薦的 UI 工具包。瞭解如何在 Compose 中顯示圖形。
在 Android 應用程式載入點陣圖較為困難的原因有很多:
- 點陣圖非常容易用光應用程式的記憶體預算。舉例來說,Pixel 手機的相機最高可拍攝 4048 x 3036 像素 (1, 200 萬像素) 的相片。
如果點陣圖設定是
ARGB_8888
,則 Android 2.3 (API 級別 9) 以上版本的預設值,將單張相片載入記憶體約需 48 MB 的記憶體 (4048*3036*4 位元組)。這種龐大的記憶體需求可能會立即用盡應用程式可用的所有記憶體。
- 在 UI 執行緒載入點陣圖可能會降低應用程式效能,進而導致回應速度變慢,甚至出現 ANR 訊息。因此,使用點陣圖時必須妥善管理執行緒。
- 如果應用程式正在將多個點陣圖載入記憶體,您必須巧妙管理記憶體和磁碟快取。否則應用程式 UI 的回應速度和流暢度可能會受到影響。
大多數情況下,我們都建議您使用 Glide 程式庫在應用程式中擷取、解碼,並顯示點陣圖。Glide 在處理上述作業,以及其他在 Android 中使用點陣圖和其他圖片的相關任務時,大多能將複雜之處化繁為簡。如要瞭解如何使用和下載 Glide,請造訪 GitHub 的 Glide 存放區。
您也可以選擇直接使用 Android 架構內建較低層級的 API。詳情請參閱「有效率地載入大型點陣圖」、「快取點陣圖」和「管理點陣圖記憶體」。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[],[],null,["# Handling bitmaps\n\nTry the Compose way \nJetpack Compose is the recommended UI toolkit for Android. Learn how to display graphics in Compose. \n[ImageBitmap →](/jetpack/compose/graphics/images/compare) \n\nThere are a number of reasons why loading bitmaps in your Android app is tricky:\n\n- Bitmaps can very easily exhaust an app's memory budget. For example, the camera on the [Pixel](https://www.android.com/phones/pixel/) phone takes photos of up to 4048x3036 pixels (12 megapixels). If the bitmap configuration used is [ARGB_8888](/reference/android/graphics/Bitmap.Config), the default for Android 2.3 (API level 9) and higher, loading a single photo into memory takes about 48MB of memory (4048\\*3036\\*4 bytes). Such a large memory demand can immediately use up all the memory available to the app.\n- Loading bitmaps on the UI thread can degrade your app's performance, causing slow responsiveness or even ANR messages. It is therefore important to manage threading appropriately when working with bitmaps.\n- If your app is loading multiple bitmaps into memory, you need to skillfully manage memory and disk caching. Otherwise, the responsiveness and fluidity of your app's UI may suffer.\n\n\nFor most cases, we recommend that you use the [Glide](https://github.com/bumptech/glide)\nlibrary to fetch, decode, and display bitmaps in your app. Glide abstracts out most of\nthe complexity in handling these and\nother tasks related to working with bitmaps and other images on Android.\nFor information about using and downloading Glide, visit the\n[Glide repository](https://github.com/bumptech/glide) on GitHub.\n\n\nYou can also opt to work directly with the lower-level APIs built into the Android framework.\nFor more information on doing so, refer to\n[Loading Large Bitmaps Efficiently](/topic/performance/graphics/load-bitmap),\n[Caching Bitmaps](/topic/performance/graphics/cache-bitmap), and\n[Managing Bitmap Memory](/topic/performance/graphics/manage-memory).\n\nMore resources\n--------------"]]