I want to load a local image file using Coil
into a Jetpack Compose Image
, but searching has produced only methods using web urls or by passing files converted to bitmap
s.
Can Coil
load a local image file directly into a Compose Image
?
I want to load a local image file using Coil
into a Jetpack Compose Image
, but searching has produced only methods using web urls or by passing files converted to bitmap
s.
Can Coil
load a local image file directly into a Compose Image
?
For the new version of coil 2.2.2, rememberImagePainter
didn't give me good results so I used this-
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(<file_path>)
.build(),
contentDescription = "icon",
contentScale = ContentScale.Inside,
modifier = Modifier.size(30.dp)
)
Hope it helps someone
You can use Coil
to load any object as a data:
val cacheFile = File(context.cacheDir, "filename")
Image(
rememberImagePainter(cacheFile),
contentDescription = "...",
)
cacheFile
via remember
? –
Iberia If you've a locally saved image path, you can try the following method,
val painter = rememberImagePainter(data = File(filePath))
Image(
painter = painter,
contentDescription = null)
and to load image from remote url,
val painter = rememberImagePainter(data = imageUrl)
Image(
painter = painter,
contentDescription = null)
© 2022 - 2024 — McMap. All rights reserved.