【发布时间】:2022-11-15 21:08:19
【问题描述】:
我正在使用 Kotlin 开发一个 Android 应用程序。我需要在屏幕上显示来自 Cloud Storage 的图片。现在,图片显示,但他们闪烁。我找不到用 Kotlin 编写的信息,我也不知道为什么会这样。 这是我当前的代码。
@Composable
fun UserInfo(navController: NavController, name: String, uid: String) {
val storage = Firebase.storage
val userRef = storage
.reference
.child("users/${uid}/photos")
.child(name)
var bitmap by remember { mutableStateOf<Bitmap?>(null) }
val ONE_MEGABYTE: Long = 1024 * 1024
userRef.getBytes(ONE_MEGABYTE).addOnSuccessListener {
bitmap = BitmapFactory.decodeByteArray(it, 0, it.size)
}
...
if (userRef != null) {
Image(
painter = rememberImagePainter(bitmap),
contentScale = ContentScale.FillBounds,
contentDescription = null,
modifier = Modifier
.width(100.dp)
.height(100.dp)
.clip(CircleShape)
)
...
有人可以帮助我吗?谢谢你。
【问题讨论】:
标签: android firebase kotlin firebase-storage android-jetpack-compose