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

Kirill Grouchnikov

11/17/2020, 5:27 AM
After filing https://github.com/JetBrains/compose-jb/issues/108 I took a look at the implementation of
ImageAsset
as
AndroidImageAsset
and how it's painted in
AndroidCanvas.drawImage
- where it is explicitly checked to be an
AndroidImageAsset
. So even though
Canvas.drawImage
accepts
ImageAsset
, it's going to accept a very specific implementation of that interface - one on Android and one on desktop. Is there a way to create an
ImageAsset
at runtime dynamically? Not from a resource, not from a file, but by populating each pixel individually as an int array, and then "wrapping" that array as an implementation of
ImageAsset
that is platform agnostic?
n

Nader Jawad

11/17/2020, 4:30 PM
ImageAsset is an interface with expect/actual function constructors for desktop and android. The ImageAsset created from non platform specific code will create a desktop ImageAsset and when drawing it will draw into the desktop based canvas which checks to see if it is an instance of Desktop ImageAsset. The android canvas implementation checks that the instance is of AndroidImageAsset. A platform implementation of compose isn't complete without having each of the mpp facilities implemented
k

Kirill Grouchnikov

11/17/2020, 4:41 PM
I understand this, but my issue is not being able to convert an array of pixels (as integers) to an image asset.