Android change camera preview size and position on SurfaceView - android

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!

Related

Clearing last frame preview on TextureView

I've displayed a camera stream using TextureView. When switching camera (stopPreview() called before switching), front-to-back or vice-versa, the view paused at the last frame drawn on the TextureView. I want to display a blank screen while the "switching" is happening. How can I achieve it?
The easiest solution is to define a black view that overlays your camera preview surface. Set it's visibility "gone" while camera preview is working, and "visible" when you stopPreview and until the switch is over. With the deprecated camera API you can use setPreviewCallbackOnce() to get the indication that it's time to hide the overlay again.

How to split camera preview in android?

I want to achieve this kind of feature.
My initial camera preview:
Now I want to break this camera preview in two parts:
What I have tried:
Create a surface view to hold preview of camera.[Done]
Shift half of the surface view out off the screen[Done] now half of the surface view shift from out off the screen and only half is visible.
The problem is camera writes it's complete preview only on visible portion of surface view so the preview gets shrink in half of the screen.
Can anybody help me how can I achieve this?
Send the camera preview to a SurfaceTexture, then draw two rects with GLES, one with the left part of the preview, one with the right. Use a single SurfaceView for display.
You can find sample code in Grafika's "texture from Camera" Activity, which manipulates the camera output in various ways. Note in particular the "zoom" feature works by displaying a progressively smaller area of the preview while keeping the output rect the same size.

Crop camera preview

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).

Camera just a portion of a SurfaceView

Is it possible to draw the camera in just a portion of the SurfaceView?
or draw different things on the same SurfaceView?
What do you want to achieve by that? You cannot send the camera preview to a portion of a SurfaceView, but you can adjust the size of this View, and put other views around it or even on top of it. The latter is an alternative to drawing different things on the same SurfaceView.

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