https://kotlinlang.org logo
#compose
Title
# compose
a

Android75

04/13/2022, 6:11 AM
I’ d like load drawable shape and have same error.
java.lang.IllegalArgumentException: Only VectorDrawables and rasterized asset types are supported ex. PNG, JPG
this is shape.
Copy code
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="<http://schemas.android.com/apk/res/android>" android:shape="oval">
    <solid android:color="#F44336"/>

</shape>
and code.
Copy code
Image(
    imageVector =   ImageVector.vectorResource(
        id = R.drawable.ball
    ),
    contentDescription = null
)
I tried with
Copy code
painter = painterResource(id = R.drawable.ball),
Copy code
var img=         ContextCompat.getDrawable(LocalContext.current, R.drawable.ball)?.toBitmap()?.asImageBitmap()
img?.let {
    Image(bitmap = img,
nothing
a

Albert Chang

04/13/2022, 6:32 AM
If you want to use drawables other than images and vectors in Compose UI, use https://google.github.io/accompanist/drawablepainter/.
Note that this drawable can easily be achieved by
Modifier.shape()
(or
Modifier.background()
) in compose and is definitely better that way.
1
a

Android75

04/13/2022, 6:44 AM
Thanks
c

Chris Sinco [G]

04/13/2022, 10:02 AM
This may also be helpful to change any SVG shape (like from a designer tool like Figma) into a Shape class: https://github.com/c5inco/shape-composer-figma This is a Figma plugin, but the repo has sample output that can give you some ideas of how to use custom paths for a Shape class, beyond rectangles
427 Views