我有 svg 图像网址,我想在 Jetpack Compose 中显示该图像。
最佳答案
您可以使用Coil SVG extension .
在 build.gradle
中添加依赖项
implementation("io.coil-kt:coil-compose:2.0.0")
implementation("io.coil-kt:coil-svg:2.0.0")
然后,将其添加到您的通话中..
@Composable
fun SvgImageSample() {
val painter = rememberAsyncImagePainter(
model = ImageRequest.Builder(LocalContext.current)
.decoderFactory(SvgDecoder.Factory())
.data("https://upload.wikimedia.org/wikipedia/commons/d/d7/Android_robot.svg")
.size(Size.ORIGINAL) // Set the target size to load the image at.
.build()
)
Image(
painter = painter,
contentDescription = null
)
}
关于android-studio - 如何在 JetPack Compose 中显示 .svg 图像 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72229339/