使用 Jetpack compose 加载本地图片
Load local image with 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)
)
它工作正常。
现在我需要加载使用 DownloadManager 下载的本地图像。
下载管理器设置为下载 Download
文件夹中的图像。它们最终位于文件夹 /storage/emulated/0/Download
中。我确认图片在那里。
问题是我不知道怎么给他们看。
我是否必须 运行 本地网络服务器才能公开它们?
我尝试使用 "file://${user.profile}"
,它适用于 Chrome,但它不起作用。
如果您有文件路径,请尝试传输文件,请尝试
val path = ...
Image(rememberImagePainter(File(path)),
contentDescription = ""
)
我在 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)
)
它工作正常。
现在我需要加载使用 DownloadManager 下载的本地图像。
下载管理器设置为下载 Download
文件夹中的图像。它们最终位于文件夹 /storage/emulated/0/Download
中。我确认图片在那里。
问题是我不知道怎么给他们看。 我是否必须 运行 本地网络服务器才能公开它们?
我尝试使用 "file://${user.profile}"
,它适用于 Chrome,但它不起作用。
如果您有文件路径,请尝试传输文件,请尝试
val path = ...
Image(rememberImagePainter(File(path)),
contentDescription = ""
)