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

Sergey Y.

02/08/2023, 11:56 PM
My observations on the state of affairs. Some time ago, quite often(480+ messages) users had the question of how to render a composable widget into a bitmap image (there are many purposes of use). But, unfortunately, there is still no single answer as to how it could be done effectively. In short, the current View system does not allow this, there's no such API. But until this moment. Android 14 DP1 is out 😲 and I think I see where this is going. New APIs have been added that perfectly match this very popular request: PixelCopy.request and PixelCopy.Request.Builder#setSourceRect(android.graphics.Rect)
PixelCopy.request
provides mechanisms that allow you to copy pixels from a
Surface/Window/View
to a
Bitmap
. It seems that this issue will finally be solved, but for users of Android 14+.
s

Sergey Y.

02/09/2023, 12:07 AM
@ephemient Previously you could only copy from SurfaceView or Window, now this API has been extended to View and you can specify the desired area to copy. Which is very suitable for Compose, as it is one view that draws components on the canvas. Correct me if I wrong.
e

ephemient

02/09/2023, 12:09 AM
PixelCopy(window, view.getLocationInWindow())
was possible before
s

Sergey Y.

02/09/2023, 12:10 AM
Then I don't know why it hasn't been used yet.
3 Views