使用 Jetpack compose 加载本地图像

655*_*536 0 android image android-jetpack-compose

我在 Android 应用程序中使用 Jetpack Compose。我需要加载图像并使用:

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)
)

Run Code Online (Sandbox Code Playgroud)

效果很好。现在我需要加载使用 DownloadManager 下载的本地图像。下载管理器设置为下载Download文件夹中的图像。它们最终位于文件夹中/storage/emulated/0/Download。我确认图像在那里。

问题是我不知道如何向他们展示。我是否必须运行本地 Web 服务器才能公开它们?

我尝试使用"file://${user.profile}"在 Chrome 上运行的 , 但它不起作用。

Ysh*_*shh 5

如果您有文件路径,请尝试传输文件,请尝试

val path = ...
Image(rememberImagePainter(File(path)),
      contentDescription = ""
)
Run Code Online (Sandbox Code Playgroud)

  • 我需要添加 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> (2认同)