Android camera preview - how to “freeze” a camera?

I'm currently trying to create an Android app for shooting, and I need to freeze the camera’s preview on this event (i.e. the picture taken) and restart it only after another event.

In other words, I want the view to display everything that the camera sees, until a freeze event occurs, and then to freeze the image (i.e. display everything that was on the screen during this event), as if photo was taken) until a defrost event occurs.

Now I use SurfaceView with SurfaceHolder.Callback to do this, and I tried to use PreviewCallback to freeze the screen, but unfortunately I can not find an example or tutorial, and I really got stuck at this point.

If anyone has a guide or some pointers on how to do this, I would really appreciate help ...

I am inserting the relevant parts of my code below:

public class CustomCameraView extends SurfaceView {

Camera camera; SurfaceHolder previewHolder; //Callback for the surfaceholder SurfaceHolder.Callback surfaceHolderListener = new SurfaceHolder.Callback() { public void surfaceCreated(SurfaceHolder holder) { camera=Camera.open(); try { camera.setPreviewDisplay(previewHolder); } catch (Throwable t) { } } public void surfaceChanged(SurfaceHolder surfaceHolder, int format, int w, int h) { Parameters params = camera.getParameters(); params.setPictureFormat(PixelFormat.JPEG); camera.setParameters(params); camera.startPreview(); } public void surfaceDestroyed(SurfaceHolder arg0) { camera.stopPreview(); camera.release(); } }; public CustomCameraView(Context ctx) { super(ctx); previewHolder = this.getHolder(); previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); previewHolder.addCallback(surfaceHolderListener); setBackgroundColor(Color.TRANSPARENT); } public CustomCameraView(Context context, AttributeSet attrs) { super(context, attrs); } protected void onDraw (Canvas canvas) { } public void closeCamera() { if(camera != null) camera.release(); } public void dispatchDraw(Canvas c) { super.dispatchDraw(c); } 

}

Many thanks for your help!

-Billy

+7
android image camera preview freeze
source share
1 answer

An old question, I know, but responsible for the offspring. You should just call

 camera.stopPreview(); 

The preview will depend on what you are watching, until you call startPreview () again.

+14
source share

All Articles