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.
Related
Can I set an ImageView to a camerapreview? Instead of using a surfaceview? I'm trying to make a camera preview semi transparent with setAlpha method, but It doesn't work on surfaceview. I mean it does work, but the camera preview is not semi transparent.
Well actually you can but not using SurfaceView. You achieve this by using GLSurface view, where you render each of your frame using shaders. In the fragment shader you can specify the opacity of your video. If you don't know OpenGL ES 2.0 you can start from here http://developer.android.com/training/graphics/opengl/index.html, but there are also many tutorial including rendering frames using opengl.
No you cannot do this, SurfaceView is the only way to create a Camera preview in Android.
I want to run android camera preview with a 640x480 resolution but display just 480x360. Right now I'm getting a stretched preview, even though I've tried to put the surface view in a frame layout or srollview. Can anyone tell me how this can be done?
A similar question has been asked before: How to crop camera preview?, but nobody answered.
Thanks
This can be achieved by using TextureView for camera preview. See https://developer.android.com/reference/android/view/TextureView.html.
Unlike SurfaceView, TextureView does not create a separate window but behaves as a regular View. This key difference allows a TextureView to be moved, transformed, animated, etc. For instance, you can make a TextureView semi-translucent by calling myView.setAlpha(0.5f).
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.
On some devices, onPreviewFrame is not called if no SurfaceView was set to display the camera preview.
However, I handle the camera in a service, so I can't set a SurfaceView but I don't want to have visible preview anyway.
How can this be done? Can I programmatically create a SurfaceView and set it with Camera::setPreviewDisplay?
This must be possible or not?
It works on almost every phone without a SurfaceView but not on HTC One X and Google Nexus One...
According to this question, creating a SurfaceView in code works fine. Though I don't think you can create it through a service.
Another approach is to create a 1px-1px SurfaceView inside a RelativeLayout and hiding it with some other view on top of it. (visibility should still be VISIBLE). We use this trick for Path camera UI where we render preview buffers through OpenGL and it works fine.
According to documentation readily configured, visible and displayed surface view is necessary to activate camera preview. It may be overlayued though
From API 11 on, you can use a SurfaceTexture instead of a SurfaceView to get frames from the camera. Then, instead of using Camera.setPreviewDisplay, simply use Camera.setPreviewTexture.
This answer as well as this one discuss this point.
I want to draw some thing on the view which we get when our camera is on in android mobile.
I do not want to take picture nor record video just that view from camera and then draw some thing on screen.
Drawing on screen will not be and issue but when we turn on camera which view we get and how can we use that view in our application?
You'll want to check androids camera-API.
You can get the preview to display in a SurfaceView or your own View-subclass, which can then be used to draw on. Some more knowledge might be found here.
You can use a RelativeLayout to put other views aligned with the surfaceView used for camera preview