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

3
  • I'm not sure if this is built in, you might need to process each frame: stackoverflow.com/questions/8620560/video-processing-in-android Commented Apr 26, 2013 at 21:24
  • Maybe adding a transparent blur image above camera surfaceView is going to be an easier solution for you? Commented Mar 6, 2014 at 15:25
  • Hi dude... You got any proper solution for that ?... because I am facing the same issue... Commented Aug 20, 2019 at 10:20

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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.
@matt_lethargic you sent me down an almost 5 week long rabbit hole from which I still haven't come out - how do you use this with a SurfaceView? It seems as if there is absolutely no way to simply convert a YUV image to a bitmap to then blur it - do you maybe have some code available? I don't know what else to do.....
@Myzel394 you're welcome :-) in my defense this post was 9 years old at the point that you read it. Unfortunately I do not have any code to share with you as I no longer code android and have forgotten most things I knew. If I was answering this these days I would be putting code in for future people so I am sorry. Best advice I can give is once in a rabbit hole for 1 week stop and try something different!
2
+50

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.

1 Comment

Being deprecated like you said is a bit risky and it's a shame no alternative was implemented from API level 14 :(.
-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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.