19

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

Nikos Hidalgo
  • 3,666
  • 9
  • 25
  • 39
user1233587
  • 2,033
  • 4
  • 24
  • 24
  • I'm not sure if this is built in, you might need to process each frame: http://stackoverflow.com/questions/8620560/video-processing-in-android – John Carter Apr 26 '13 at 21:24
  • Maybe adding a transparent blur image above camera surfaceView is going to be an easier solution for you? – Devrim Mar 06 '14 at 15:25
  • Hi dude... You got any proper solution for that ?... because I am facing the same issue... – tejraj Aug 20 '19 at 10:20

3 Answers3

2

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.

trumpetlicks
  • 7,033
  • 2
  • 19
  • 33
matt_lethargic
  • 2,706
  • 1
  • 18
  • 33
  • While I think that would work it's a shame it was only added in API level 17, when I personally need it in API level 16. – Pete Mar 07 '14 at 21:39
2

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.

trumpetlicks
  • 7,033
  • 2
  • 19
  • 33
  • Being deprecated like you said is a bit risky and it's a shame no alternative was implemented from API level 14 :(. – Pete Mar 07 '14 at 21:40
-4

You have to change the camera parameters; in this case with Camera.Parameters.setPictureSize().

The basic workflow here is :

Camera.Parameters cp = mCamera.getParameters(); // get the current params
cp.set...(); // change something
mCamera.setParameters(cp); // write the params back

Make sure that every resolution that you set via this function is supported. You can get a list of the resolutions that are supported on a device via Camera.Parameters.getSupportedPictureSizes(). and check this Camera documentation.

Harshit Rathi
  • 1,862
  • 2
  • 18
  • 25