Picture function draws picture out of resource id; like R.drawable.icon
.
@Composable
fun Picture(@DrawableRes resId: Int, modifier: Modifier = Modifier) {
val rectModifier = loadVectorResource(resId).resource.resource
?.let { asset ->
modifier.paint(
painter = VectorPainter(asset)
)
}
?: modifier
Box(modifier = rectModifier)
}
How can I change this, so it takes a Drawable
argument instead of an @DrawableRes
?
I am not sure about your scenario, to which you need
Drawable
instead of the given API.But we can achieve using the following way.
Modifier.paint
need just aPainter
Object, Painter we can create using bothImagePainter
andVectorPainter
.In our case, we want to use Drawable, so we can use
ImagePainter
and its needImageAsset
, so we can useBitmap
to createImageAsset
.So the final result will be like: