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
But there seems to be no way to do it
Couple things come to mind but I am not sure how to achieve it
use a blur overlay and place it on top of the surface view, but how do u create such blur overlay?
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
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.
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.
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.
Related
You might consider this question a sequel to this other one I've recently asked. I have a custom device with a front camera that is mirrored by default and I would like it to always behave like it was flipped horizontally. Note that the end goal of my app is to perform face, barcode and facemask detection (the last one with a custom .tflite model), and I'm trying to understand if it's possible with the current state of CameraX and the quirks of the device I'm using.
For the preview, I can force PreviewView to use a TextureView by calling PreviewView#implementationMode = PreviewView.ImplementationMode.COMPATIBLE so I can just call PreviewView#setScaleX(-1) and it gets displayed like I want.
For taking pictures, I haven't tried yet but I know I can pass setReversedHorizontal(true) to the ImageCapture.OutputFileOptions used in the ImageCapture.Builder, so the image should be saved in reverse.
For image analysis I really don't know. If the input image is taken directly from the preview stream, then it should still be in its default state because PreviewView#setScaleX(-1) only flips the View on screen, right? So in my Analyzer's analyze() I would need to convert the ImageProxy#image to bitmap, then flip it and pass the result to InputImage.fromBitmap().
Is this everything I need? Is there a better way to do this?
In my Android-Unity app I have some data such as text, text size, text coordinates etc that I will use to create the output and store it as a screenshot I will later use in my app.
But I need to make this happen when the user isn't seeing the Unity player/scene. So my question is that is it possible to render the contents and then take a screenshot of the same without the user seeing the Unity editor/player/scene whatever one may call it? Is there a way to do it in the background? Thanks!
I'm not sure exactly what you're trying to accomplish but I can clarify the use of a culling mask here. Here is what the scene looks like. I have embedded the view from Camera 2 into the bottom left of the game. You can see that Camera 2 is not displaying the floor. This is because I set it's culling to only respond to objects tagged with a custom layer here. Where as the Main Camera's culling mask is set to everything. Now, anything I tag with the "Custom" layer will be visible in the second camera and everything else would not be. I'm assuming what you want to do from here is to tag the things you want visible when you take a screenshot with a specific layer, then set the Culling Mask of your "Screenshot Camera" to that layer and take a screenshot with that Camera. That way you can specify what Objects/UI want visible in that camera.
iam currently using camera and surfaceview in my app to use Torch etc ... , im using these in an Activity ,
How to use Camera and SurfaceView in Background , ex . : I want to keep Torch/Led Flash On , i saw many Widget that work fine in Background , how they do it ?
Thanks .
Take a look here:
http://developer.android.com/guide/topics/media/camera.html
There is all the code you need to make an activity which shows the camera preview.
As the Camera API:
http://developer.android.com/reference/android/hardware/Camera.html#setPreviewDisplay%28android.view.SurfaceHolder%29
specifies...you need to use a SurfaceHolder for your preview. Thus you can only use a SurfaceView or a derived class for your automatic preview. Otherwise you can use for example a TextureView or an ImageView to draw your preview by yourself. You'll need though to implement the onFramePreview method to grab the frames from the preview and handle them by yourself. By using OpenGL or the ANI API you can also add effects to your frame. This is the only way, I know about, to also add effects directly on your preview, unless these effects can be achieved by overlaying a semi-transparent colored surface above your preview image.
I'm doing a color detector with the Android Camara and need a good parameters configuration that show me a realistic color. For example, I focus in a black shirt, but the camara take the light and change the color to light gray and i don't want it.
If someone knows how to make a good configuration I would appreciate it.
I can't say I have done it myself but I think you would need to have an Activity whose sole purpose would be to do calibration. You would be getting a live Camera feed and prompt the user to press + or - if the shirt is the black they want. The +/- would be augmenting a Color matrix filter applied to the camera view. It might be simpler to take a picture and work with the captured bitmap than it would be for the live camera feed.
I use the android camera and allow the user to take stills, but I would also like to also allow the user to toggle the ability to use flash. From off/on/auto
This button will be overlayed on the camera just like in the default android camera application. But I do not want to use that application.
How would I do this? I understand Camera.Parameters, but if I added a button on the layout that added key/value pairs to camera.parameters, would I need to refresh the camera? I will eventually try this (sometimes just typing out problems helps me come up with ideas), but any insight would be appreciated!
You can change the Camera parameters at any time (after you have your camera object).
http://developer.android.com/reference/android/hardware/Camera.Parameters.html
Use whatever settings you want, and attach them to whatever you want your buttons to look like. It's 100% straight forward.
here's a sample from something I did...
Camera.Parameters cp = mCamera.getParameters();
cp.setJpegQuality(100);
cp.setColorEffect(Parameters.SCENE_MODE_PORTRAIT);
cp.setFlashMode(Parameters.FLASH_MODE_ON);
cp.setColorEffect(Parameters.EFFECT_MONO);
setPictureSize(cp);
mCamera.setParameters(cp);
You can call setParameters at any time, and they will take effect immediately.