Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android blur surfaceview used in camera

I have a camera preview in my android app. As you all probably know it is implemented by a surfaceview in android.

In my photo app, which allows users to take pictures, I want to blur the camera preview (the surface view) if the user has not logged in yet if the user is logged in, I will display the normal preview (without blur)

Blur as something like

enter image description here

But there seems to be no way to do it

Couple things come to mind but I am not sure how to achieve it

  1. use a blur overlay and place it on top of the surface view, but how do u create such blur overlay?
  2. another approach is to change the attribute of the window, but I can't do it to surfaceview,

     getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
    

So can we create a window overlay the surfaceview and set the flag like that? I don't think so

can someone tell me how to blur a camera preview, which is a surface view

note: I am trying to blur an area which is the output from camera preview, so it is not like I am blurring a static image, the blur area will change depending on where you point your phone camera

like image 646
user1233587 Avatar asked Mar 22 '13 08:03

user1233587


People also ask

How do you blur the camera on an android?

You simply open the camera > tap menu > select “portrait” option > take your picture > tap the thumbnail to select the image you just captured > Google automatically adds the blur background effect to the image.

What is SurfaceView android?

Provides a dedicated drawing surface embedded inside of a view hierarchy. You can control the format of this surface and, if you like, its size; the SurfaceView takes care of placing the surface at the correct location on the screen.

How to enable blur in android 12?

Navigate to Settings -> System -> Developer options -> Hardware accelerated rendering -> Allow window-level blurs. If you can't find the option there, the blurs aren't supported on your device.


2 Answers

The best way to do this is to take a screen shot of the control, apply a blur to it, and then show that image over the top of the original control. This is how the yahoo weather app does it and its how google suggest you do things like this.

Render script does bluring fast. I've also got some code, but it's not currently at hand right now.

These might help:

http://blog.neteril.org/blog/2013/08/12/blurring-images-on-android http://docs.xamarin.com/recipes/android/other_ux/drawing/blur_an_image_with_renderscript/

I've also read that there are methods built into Android that do this, but the API isn't public so we cannot use it... which sucks.

like image 177
matt_lethargic Avatar answered Sep 30 '22 14:09

matt_lethargic


Although your 2nd option is losing support in later versions of the Android OS, it may be a good option. I would think to bring a window IN FRONT of your surfaceview, and use the blur_behind property of your now new IN FRONT window.

Android API documentation " This constant was deprecated in API level 14. Blurring is no longer supported.

Window flag: blur everything behind this window.

Constant Value: 4 (0x00000004)"

I do have to admit, Im not 100% sure this would work, but its definitely worth a try.

like image 27
trumpetlicks Avatar answered Sep 30 '22 13:09

trumpetlicks