【发布时间】:2023-04-02 01:47:01
【问题描述】:
我无法在 Jetpack Compose 中使用 Coil 在 Image 中加载 this image
【问题讨论】:
标签: kotlin svg android-jetpack-compose coil
我无法在 Jetpack Compose 中使用 Coil 在 Image 中加载 this image
【问题讨论】:
标签: kotlin svg android-jetpack-compose coil
Coil 默认不支持 SVG。
根据documentation,您需要:
添加以下依赖:
implementation("io.coil-kt:coil-svg:$coil_version")
设置SvgDecoder为解码器:
rememberImagePainter(
data = svgImageUrl,
builder = {
decoder(SvgDecoder(LocalContext.current))
}
),
附言请注意,如果您以这种方式设置解码器,Coil 将无法在此 Painter 中处理非 SVG 图像,因此如果您想要一些通用的解决方案,您应该检查 url 扩展名并相应地添加解码器。
【讨论】: