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
Drawableinstead of the given API.But we can achieve using the following way.
Modifier.paintneed just aPainterObject, Painter we can create using bothImagePainterandVectorPainter.In our case, we want to use Drawable, so we can use
ImagePainterand its needImageAsset, so we can useBitmapto createImageAsset.So the final result will be like: