简体   繁体   中英

Load local image with Jetpack compose

I'm using Jetpack Compose in an Android app. I need to load images and I use:

Image(
    modifier = centerHorizontal
        .size(AppSize.profileImage)
        .border(
            width = AppSize.line,
            color = Color.White,
            shape = AppCircleShape()
        ),
    painter = rememberImagePainter(
        data = profile.image,
        builder = {
            transformations(CircleCropTransformation())
        }
    ),
    contentDescription = stringResource(id = R.string.profile_image)
)

It works fine. Now I need to load local images that I have downloaded using the DownloadManager. The download manager is set up to download the images in the Download folder. They end being in the folder /storage/emulated/0/Download . I verified that the images are there.

The problem is that I don't know how to show them. Do I have to run a local web server to expose them?

I tried to use "file://${user.profile}" , that works on Chrome, but it doesn't work.

If you have a file path, try to transfer the file,please try

val path = ...
Image(rememberImagePainter(File(path)),
      contentDescription = ""
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM