1

I have svg image Url, I want to display the image in Jetpack Compose.

Dev
  • 11
  • 2
  • You can check this comment https://stackoverflow.com/questions/70835321/how-to-load-svg-images-in-compose-properly – Aanal Shah May 13 '22 at 12:09

1 Answers1

2

You can use the Coil SVG extension.

Add the dependencies in your build.gradle

implementation("io.coil-kt:coil-compose:2.0.0")
implementation("io.coil-kt:coil-svg:2.0.0")

Then, add it to your call..

@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
    )
}
nglauber
  • 18,674
  • 6
  • 70
  • 75