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

Rafs

11/11/2020, 9:21 PM
How can I create an
ImageAsset
from a
Bitmap
object?
i

Ian Lake

11/11/2020, 10:35 PM
r

Rafs

11/11/2020, 10:52 PM
Thank you
@Ian Lake is there also a way of converting a
VectorAsset
created with
vectorResource(..)
into an
ImageAsset
?
i

Ian Lake

11/12/2020, 12:22 AM
Generally those aren't interchangeable things so the previous guidance has been that any API that takes an
ImageAsset
should have another overload that takes a
VectorAsset
(that's how
Icon
works for instance). I know there's been some recent work in this space - maybe @Nader Jawad has more info?
r

Rafs

11/12/2020, 12:24 AM
@Ian Lake I've been trying to draw a vector asset onto the canvas using
drawImage
but it's only accepting an
ImageAsset
and not a
VectorAsset
n

Nader Jawad

11/12/2020, 12:32 AM
You can draw a VectorAsset by creating a VectorPainter from it and calling draw into a target canvas
Icon and Image already have convience methods to consume VectorAsset instances directly and create a VectorPainter on your behalf
You can create a VectorPainter by calling
rememberVectorPainter(myVectorAsset)
within a composable method
r

Rafs

11/12/2020, 12:40 AM
Thank you @Nader Jawad
c

cb

11/12/2020, 7:31 AM
@Manuel Vivo and I went through recently in this talk (about 18:00) https://chris.banes.dev/talks/2020/compose-for-existing-apps-dcemea/
2 Views