rob42
05/20/2024, 9:20 AMBlurEffect
gets applied on the graphics layer, which I only have 1 of. So either both bitmaps are blurred, or none are.
Is there a trick I'm missing here? Seems like I could solve this if I could have 2 graphics layers that are siblingsSergey Y.
05/20/2024, 9:39 AMBlurEffect
works for API 32 and above, but there is a backward-compatible way for older Android versions. Although it is software-based, but should be fine for still images.
Here's how you can achieve the blur effect on older Android versions:
1. Render the GraphicsLayer
into a bitmap using the .toImageBitmap()
method.
2. Use the drawBehind
modifier to draw the bitmap using a Paint
object with a BlurMaskFilter
applied to it.
If you want to proceed with the BlurEffect
anyway, you need to draw the GraphicsLayer
into two different `RenderNode`s:
• One RenderNode for the content.
• Another RenderNode for the blur effect.
You can see Haze library as an example.rob42
05/20/2024, 9:42 AMSergey Y.
05/20/2024, 9:42 AMSergey Y.
05/20/2024, 9:43 AMrob42
05/20/2024, 9:50 AMrob42
05/20/2024, 9:50 AMSergey Y.
05/20/2024, 9:53 AMrob42
05/20/2024, 9:55 AMSergey Y.
05/20/2024, 9:57 AMrob42
05/20/2024, 10:07 AM2. Use theI'm curious how this is done actually. I don't see a way to pass paint tomodifier to draw the bitmap using adrawBehind
object with aPaint
applied to it.BlurMaskFilter
drawImage
when drawing the bitmap?
The docs say "The image is composited into the canvas using the given Paint
." -- but there is no paint parameter to specify?Sergey Y.
05/20/2024, 10:15 AMdrawImage
when drawing the bitmap?
You need to use drawIntoCanvas { canvas -> }
to access Canvas object directly.rob42
05/20/2024, 10:17 AMSergey Y.
05/20/2024, 10:23 AMSergey Y.
05/20/2024, 10:23 AMrob42
05/20/2024, 11:07 AMSergey Y.
05/20/2024, 11:09 AMSergey Y.
05/20/2024, 11:10 AMrob42
05/20/2024, 11:10 AMrob42
05/20/2024, 11:12 AMrob42
05/20/2024, 11:13 AMSergey Y.
05/20/2024, 11:13 AMrob42
05/20/2024, 11:16 AMrob42
05/20/2024, 11:16 AMrob42
05/20/2024, 11:22 AMSergey Y.
05/20/2024, 1:41 PM