Michael Paus
01/26/2024, 11:49 AM@OptIn(ExperimentalResourceApi::class)
@Composable
fun appIconPainter(): Painter {
val painter1 = org.jetbrains.compose.resources.painterResource(Res.drawable.appicon)
val painter2 = androidx.compose.ui.res.painterResource("drawable/appIcon.svg")
return painter2
}
Calling this method results in an exception during the creation of painter1.
Exception in thread "main" java.lang.IllegalArgumentException: Failed to Image::makeFromEncoded
at org.jetbrains.skia.Image$Companion.makeFromEncoded(Image.kt:137)
at org.jetbrains.compose.resources.ImageResources_skikoKt.toImageBitmap(ImageResources.skiko.kt:8)
at org.jetbrains.compose.resources.ImageResourcesKt$imageResource$imageBitmap$3$cached$1.invoke(ImageResources.kt:77)
at org.jetbrains.compose.resources.ImageResourcesKt$imageResource$imageBitmap$3$cached$1.invoke(ImageResources.kt:76)
at org.jetbrains.compose.resources.ImageResourcesKt$loadImage$2$deferred$1$1$1.invokeSuspend(ImageResources.kt:134)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:281)
at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38)
at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
at org.jetbrains.compose.resources.ResourceState_blockingKt.rememberResourceState(ResourceState.blocking.kt:15)
at org.jetbrains.compose.resources.ImageResourcesKt.imageResource(ImageResources.kt:74)
at org.jetbrains.compose.resources.ImageResourcesKt.painterResource(ImageResources.kt:58)
at ModelBridgeImpl.appIconPainter(main.desktop.kt:139)
However, if I just comment out the offending line for painter1 the code works as expected. It seems that the jetbrains variant of painterResource does not like SVGs.
The resources are located as seen in the screenshot and I can access the other PNG file without problem.Konstantin Tskhovrebov
01/26/2024, 11:52 AMKonstantin Tskhovrebov
01/26/2024, 11:53 AMMichael Paus
01/26/2024, 12:12 PMandroidx
variant of painterResource has always supported SVGs. Why is the Jetbrains resource handling more picky?Konstantin Tskhovrebov
01/26/2024, 12:13 PMZach Klippenstein (he/him) [MOD]
01/26/2024, 6:56 PM