create agent
This commit is contained in:
@@ -3,6 +3,7 @@ package com.aiosman.ravenow.ui.composables
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -10,6 +11,7 @@ import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
@@ -57,11 +59,11 @@ fun CustomAsyncImage(
|
||||
|
||||
val imageLoader = getImageLoader(context ?: localContext)
|
||||
|
||||
// 处理 imageUrl 为 null 的情况
|
||||
if (imageUrl == null|| imageUrl == "") {
|
||||
// 处理 imageUrl 为 null 或空字符串的情况
|
||||
if (imageUrl == null || imageUrl == "") {
|
||||
// 如果 imageUrl 为 null 且有占位符,则直接显示占位符
|
||||
if (placeholderRes != null) {
|
||||
androidx.compose.foundation.Image(
|
||||
Image(
|
||||
painter = androidx.compose.ui.res.painterResource(placeholderRes),
|
||||
contentDescription = contentDescription,
|
||||
modifier = modifier,
|
||||
@@ -70,6 +72,19 @@ fun CustomAsyncImage(
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 处理 Bitmap 类型
|
||||
if (imageUrl is Bitmap) {
|
||||
Image(
|
||||
bitmap = imageUrl.asImageBitmap(),
|
||||
contentDescription = contentDescription,
|
||||
modifier = modifier,
|
||||
contentScale = contentScale
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理字符串URL
|
||||
AsyncImage(
|
||||
model = ImageRequest.Builder(context ?: localContext)
|
||||
.data(imageUrl)
|
||||
|
||||
Reference in New Issue
Block a user