Crop camera preview - 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).

Related

Display camera preview in a circle

I want to display a camera preview in a circular shape using the camera2 api. I want to display the preview in a circular shape, but I dont't want the image to be captured in a circular shape.
The captured image would be a face( later want to implement face detection and auto capture). I did have a look at few questions already asked, but none of them are with the new camera2 api's and most of them talk about having an overlay image cropped with a transparent circle. But this will not work in a case where I need to auto detect a face(as the face may appear out side the cropped circular image).
Is there any way I can implement this ? I did try an example with TextureView and set it to a LinearLayout with fixed width and height, but the preview appeared a bit squeezed and in a square shape.
I don't see why face detection matters here - if you enable the camera API's face detector, it'll run on the full image no matter what you do in drawing it inside a circle.
You can either use a circle overlay on top of a correctly-shaped TextureView or SurfaceView, or do your own OpenGL rendering of a circle with the camera preview as a EGL texture.
The latter you'll probably want a GLSurfaceView for the OpenGL drawing context, and a SurfaceTexture to send camera data to and expose it as a EGL texture.
JPEGs captured will still be full-FOV, and the camera API will know nothing about your circular preview drawing, so face detection and everything else will work on the full field of view.

Android: SurfaceView resolution is lower than screen resolution

I am following a tutorial on http://obviam.net/index.php/a-very-basic-the-game-loop-for-android/ to make an Android game loop. It works really well, except that my SurfaceView is only 526x320 while my phone is 1920x1080 resolution. Can anyone help me fix this issue?
First, that tutorial overrides onDraw() when rendering onto a SurfaceView Surface, which is a recipe for trouble. Don't do that. Don't extend SurfaceView unless you really want to draw on the View as well as the Surface. (Its render thread may also continue to run while the app isn't in the foreground... maybe you should find a tutorial by someone who understands SurfaceView better.)
Second, the SurfaceView's Surface is allowed to be a different size. You can set it to any (reasonable) size you want with the setFixedSize() method.
The default size of the SurfaceView should match the size of the View. If you have a full-screen View, the Surface will be the size of the screen.

Android change camera preview size and position on SurfaceView

I want to make an application that shows a camera preview on a surface view. the SurfaceView fills the screen, but I want to show the preview only on a certain position of the screen, in a smaller square. I want to draw other things later on the surfaceview too, around the preview. My problem is that the preview fills the whole surfaceview. Is there a way to resolve this problem? I read that I can't use more than one SurfaceView at the same time to separate the preview and the drawing.
Thank you for your help!

Android: onPreviewFrame never called without SurfaceView

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.

How to draw on top of camera preview?

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

Categories

Resources