【问题标题】:How to load remote SVG image using Coil in Jetpack Compose如何在 Jetpack Compose 中使用 Coil 加载远程 SVG 图像
【发布时间】:2023-04-02 01:47:01
【问题描述】:

我无法在 Jetpack Compose 中使用 Coil 在 Image 中加载 this image

【问题讨论】:

    标签: kotlin svg android-jetpack-compose coil


    【解决方案1】:

    Coil 默认不支持 SVG。

    根据documentation,您需要:

    1. 添加以下依赖:

      implementation("io.coil-kt:coil-svg:$coil_version")
      
    2. 设置SvgDecoder为解码器:

      rememberImagePainter(
          data = svgImageUrl,
          builder = {
              decoder(SvgDecoder(LocalContext.current))
          }
      ),
      

    附言请注意,如果您以这种方式设置解码器,Coil 将无法在此 Painter 中处理非 SVG 图像,因此如果您想要一些通用的解决方案,您应该检查 url 扩展名并相应地添加解码器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-29
      • 2022-08-06
      • 2022-10-06
      • 1970-01-01
      • 1970-01-01
      • 2019-11-08
      • 1970-01-01
      • 2021-07-01
      相关资源
      最近更新 更多