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

Nikit Bhandari

04/09/2020, 7:12 PM
Copy code
drawImage(imageResource(R.drawable.baseline_menu_white_18dp)
        , Offset(midX, midY), Paint().apply { color = Color(25, 138, 128) })
When I call the above
drawImage
method of Canvas, my build fails with the following error
Functions which invoke @Composable functions must be marked with the @Composable annotation
But Canvas already has the @Composable annotation, any clue what I might be missing here? Thanks
l

Louis Pullen-Freilich [G]

04/09/2020, 7:24 PM
The lambda body of
Canvas
:
Copy code
onCanvas: DrawScope.() -> Unit
Is not
Composable
, and you are calling
imageResource
inside this lambda, which is a
Composable
function. So you will need to write something like:
Copy code
val image = imageResource(R.drawable.baseline_menu_white_18dp)

Canvas {
    drawImage(image)
}
👍 1
☝️ 3
7 Views