Hi how can we make blur effect with a hole? I want...
# compose
r
Hi how can we make blur effect with a hole? I want to blur outside a box on a live camera

https://i.stack.imgur.com/fwlgM.gif

r
@Jonas thank you But I want to blur outside a box on a live camera
I’m digging into runtime shaders
l
I think you need shader atm
z
Make whole screen blurred and use Modifier.magnifier set its shape circle and zoom factor 1F
r
@Zaki Shaikh can you share a sample code?
t
@rsktash did you tried to blur the complete camera image and than draw original image ontop of the section you do not want to be blurred? Not sure if this works performance wise.
r
@Timo Drick No I need live camera blurring
t
Yes i know. But you can intercept the camera image and draw it yourself.
r
This is not performance efficient
t
If you do the blur without hardware support it is very expensive performance wise yes. But just drawing an image is not expensive. And the build in code also just do the same.
Maybe instead of blur you could just darken the image or s.th. similar?
r
I’ve implemented this for older devices
t
Or maybe you use a lower framerate for the blurred image compared to the non blured part.
Normally you could also fake a blur by resize the image to a smaller version and blur this. And than rescale it. But at the end you need hardware support for the blur otherwise it will not be usable for live images.
Not sure if this is possible to reach with Compose but you could use an SurfaceView with opengl support inside of compose. But of course very complex project than.
r
You can use the built-in blur render effect on Android 13 or write a custom blur shader with agsl (although it won't be as efficient as the built in blur shader since it's multi pass; you might be able to do the same thing by chaining runtime shader effects though)
To make that work on a camera view finder the easiest thing to do is to have the camera render into a TextureView
It does come at a bandwidth/power cost however. The most efficient solution is what Timo mentioned and to use OpenGL or Vulkan to do a custom blur directly into a SurfaceView using the camera image as an external texture
Oh wait I forgot you can also setup the camera to stream into a hardware bitmap, which doesn't require a TextureView
t
@rsktash if you want to go the OpengGl route i could provide you some code. I optimized the blur a little bit to be fast even for big images. But i use it only for a static image that is saved inside of a texture. Just sent me a PM if you are interessted.
r
Hi @Timo Drick I’ve achieved it with runtime shaders using agsl syntax
For older androids using dimm effect
c
sick. show a VIDEO!!!
r
236 Views