Coil为何无法从存储库加载图像?

huangapple go评论74阅读模式
英文:

Why Coil is not loading Images from Repository?

问题

我正在使用Coil库从Firebase加载图像到我的项目中。小尺寸的图像可以成功加载,但大尺寸的图像无法加载。我已尝试了一切方法,但不知道为什么这些图像无法加载。这是我的代码:

@Composable
fun AdvertisementBanner(advertiseList: List<Categories>) {
    Box(
        modifier = Modifier
            .fillMaxWidth()
            .height(200.dp)
    ) {
        Banner(advertiseList = advertiseList)
    }
}

@Composable
fun Banner(advertiseList: List<Categories>) {
    LazyRow(
        modifier = Modifier.height(200.dp),
        horizontalArrangement = Arrangement.spacedBy(3.dp)
    ) {
        items(advertiseList.size) {
            if (advertiseList[it].type == "AdvertisementBanner") {
                BannerItem(
                    backgroundColor = Color.White,
                    imagePainter = advertiseList[it].url!!
                )
            }
        }
    }
}

@Composable
fun BannerItem(
    backgroundColor: Color,
    imagePainter: String
) {
    Card(
        modifier = Modifier
            .width(300.dp)
            .padding(5.dp),
        elevation = CardDefaults.cardElevation(
            defaultElevation = 5.dp
        ),
        colors = CardDefaults.cardColors(
            containerColor = Color.White
        )
    ) {
        LoadImages(imagePainter)
    }
}

@Composable
fun LoadImages(imagesUrl: String?) {
    AsyncImage(
        model = imagesUrl, contentDescription = "repository images", contentScale = 
        ContentScale.Fit, modifier = Modifier.width(300.dp)
    )
}

请告诉我如何修复它。

英文:

I am using Coil library to load images from Firebase in my project. Small Images are able to load successfully but large size images are not loading. I have tried all ways to make it happen but not getting why these are not loading. This is my code

@Composable
fun AdvertisementBanner(advertiseList: List&lt;Categories&gt;) {
Box(
    modifier = Modifier
        .fillMaxWidth()
        .height(200.dp)
 ) {
    Banner(advertiseList = advertiseList)
   }
 }



  @Composable
 fun Banner(advertiseList: List&lt;Categories&gt;) {
  LazyRow(
    modifier = Modifier.height(200.dp),
    horizontalArrangement = Arrangement.spacedBy(3.dp)
   ) {
    items(advertiseList.size) {
        if (advertiseList[it].type == &quot;AdvertisementBanner&quot;) {
            BannerItem(
                backgroundColor = Color.White,
                advertiseList[it].url!!
             )
          }
       }
     }
  }

 @Composable
 fun BannerItem(
 backgroundColor: Color,
  imagePainter: String
  ){
  Card(
    modifier = Modifier
        .width(300.dp)
        .padding(5.dp),
    elevation = CardDefaults.cardElevation(
        defaultElevation = 5.dp
    ),
    colors = CardDefaults.cardColors(
        containerColor = Color.White
      )
     ) {
        LoadImages(imagePainter)
   }
 }

 @Composable
 fun LoadImages(imagesUrl: String?) {
    AsyncImage(
        model = imagesUrl, contentDescription = &quot;repository images&quot;, contentScale = 
   ContentScale.Fit, modifier = Modifier.width(300.dp)
     )
   }

Please tell me how do i fix it.

答案1

得分: 1

I use coil like this to load bigger images. give it a try, hope it works.

英文:
val painter = rememberAsyncImagePainter(
            ImageRequest.Builder(LocalContext.current).data(data = imgUrl)
                .apply(block = fun ImageRequest.Builder.() {
                    placeholder(placeholder)
                    scale(Scale.FILL)
                }).build()
        )
        Image(
            painter = painter,
            contentDescription = contentDescription,
            mod.fillMaxSize(),
            contentScale = scale
        )

I use coil like this to load bigger images. give a a try, hope it works.

huangapple
  • 本文由 发表于 2023年3月7日 02:26:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75654507.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定