I would like to load saved image on cache into Image
of Jetpack Compose using Coil. I searched in stackoverflow but all suggested ways are for loading web urls. I know that It's possible to convert image file to bitmap and then pass it to Coil but is there any builtin solution for it?
Asked
Active
Viewed 1.1k times
7

Vahid
- 1,588
- 4
- 22
- 34
-
Where are stored these files? – Gabriele Mariotti Sep 13 '21 at 08:45
-
@Gabriele Mariotti on cache folder – Vahid Sep 13 '21 at 08:48
3 Answers
8
You can use Coil
to load any object as a data:
val cacheFile = File(context.cacheDir, "filename")
Image(
rememberImagePainter(cacheFile),
contentDescription = "...",
)

Gabriele Mariotti
- 320,139
- 94
- 887
- 841
7
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

Priya Sindkar
- 368
- 3
- 11
4
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)

Murodjon Abdukholikov
- 417
- 5
- 18