androidandroid-jetpack-composecoil

How to load Image Files into Jetpack Compose Image using Coil


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 bitmaps.

Can Coil load a local image file directly into a Compose Image?


Solution

  • 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