Handling bitmaps
Stay organized with collections
Save and categorize content based on your preferences.
Try the Compose way
Jetpack Compose is the recommended UI toolkit for Android. Learn how to display graphics in Compose.
There are a number of reasons why loading bitmaps in your Android app is tricky:
- Bitmaps can very easily exhaust an app's memory budget. For example, the
camera on the Pixel phone takes
photos of up to 4048x3036 pixels (12 megapixels).
If the bitmap configuration used is
ARGB_8888
,
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.
- 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.
- 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.
For most cases, we recommend that you use the Glide
library to fetch, decode, and display bitmaps in your app. Glide abstracts out most of
the complexity in handling these and
other tasks related to working with bitmaps and other images on Android.
For information about using and downloading Glide, visit the
Glide repository on GitHub.
You can also opt to work directly with the lower-level APIs built into the Android framework.
For more information on doing so, refer to
Loading Large Bitmaps Efficiently,
Caching Bitmaps, and
Managing Bitmap Memory.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-06-27 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
{"lastModified": "Last updated 2024-06-27 UTC."}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-06-27 UTC."]]