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

Evgeniy Shmoilov

02/07/2021, 8:01 PM
Hi! Is there a way to get pixel color on
Canvas
by coordinates?
👀 1
a

Adam Powell

02/07/2021, 8:48 PM
What is your use case? Generally it is quite slow to read pixels back from GPU memory. If you are working from source data like an image or other data derived from app state, it's better to get what you need from there instead of from final pixels.
r

romainguy

02/07/2021, 9:00 PM
Getting a pixel color would mean interrupting command recording, flushing the command buffer to the render thread then GPU, then wait for frame completion for readback, all the while blocking the main thread
That or you'd get the previous frame's color (which may not exist)
A cheaper way is to draw what you want to draw in a Bitmap (it can even be 1x1) and read back from that
e

Evgeniy Shmoilov

02/08/2021, 6:27 AM
I am implementing a recursive flood fill algorithm as part of a lab
r

romainguy

02/08/2021, 6:37 AM
You should do this on a
Canvas
that wraps a
Bitmap
then
Or better yet, directly in an array of integers that you then convert to a
Bitmap
k

Kyant

02/09/2021, 12:54 AM
Is there a way to convert Composables to Bitmap?
r

romainguy

02/09/2021, 2:10 AM
You can use a ComposeView to host your composables and draw that view into a Bitmap
k

Kyant

02/09/2021, 4:33 AM
Oh, I crashed with "width and height must be > 0"
r

romainguy

02/09/2021, 5:53 PM
Well how big is your Bitmap? 🙂
k

Kyant

02/09/2021, 11:11 PM
The problem has been resolved. 😀
I see there is a Modifier.blur() proposal in the issue tracker, when it will be implemented?
r

romainguy

02/10/2021, 3:42 AM
Any updates will be posted on the bug
11 Views