Loading Images - Jetpack Compose - Android Developers
Loading Images - Jetpack Compose - Android Developers
Loading images
Load an image from the disk
Use the Image (/reference/kotlin/androidx/compose/foundation/package-summary#Image)
composable to display a graphic on screen. To load an image (for example: PNG, JPEG,
WEBP) or vector resource from the disk, use the painterResource
(/reference/kotlin/androidx/compose/ui/res/package-summary#painterresource) API with your
image reference. You don't need to know the type of the asset, just use
painterResource in Image or paint modifiers.
DrawScope :
Image(
painter = painterResource(id = R.drawable.dog),
contentDescription = stringResource(id = R.string.dog_content_description
)
/snippets/src/main/java/com/example/compose/snippets/images/LoadingImagesSnippets.kt#L47-L50)
Drawable support
painterResource currently supports the following drawable types:
AnimatedVectorDrawable (/reference/android/graphics/drawable/AnimatedVectorDrawable)
https://developer.android.com/develop/ui/compose/graphics/images/loading 1/3
8/9/24, 10:34 AM Loading images | Jetpack Compose | Android Developers
ColorDrawable (/reference/android/graphics/drawable/ColorDrawable)
VectorDrawable (/reference/android/graphics/drawable/VectorDrawable)
AsyncImage(
model = "https://example.com/image.jpg",
contentDescription = "Translated description of what the image contains"
)
/snippets/src/main/java/com/example/compose/snippets/images/LoadingImagesSnippets.kt#L58-L61)
Coil Glide
(https://github.com/coil-kt/coil#jetpack- (https://bumptech.github.io/glide/int/compose.h
compose) tml)
An image loading library backed by Kotlin A fast and efficient image loading library
Coroutines (Instacart). for Android focused on smooth scrolling
maven-central v2.7.0
(Google).
(https://search.maven.org/artifact/io.coil-kt/coil- maven-central v1.0.0-beta01
compose) (https://search.maven.org/artifact/com.github.bu
mptech.glide/compose)
https://developer.android.com/develop/ui/compose/graphics/images/loading 2/3
8/9/24, 10:34 AM Loading images | Jetpack Compose | Android Developers
Previous
arrow_back Overview (/develop/ui/compose/graphics/images)
Next
ImageBitmap vs ImageVector (/develop/ui/compose/graphics/images/compare) arrow_forward
Content and code samples on this page are subject to the licenses described in the Content License
(/license). Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://developer.android.com/develop/ui/compose/graphics/images/loading 3/3