Should I reopen the camera before resizing the surface

I am working on a custom camera app and am using FrameLyout

to display a preview. In one part of the application, I have to dynamically resize Preview

and FrameLayout

. These are the steps I take before changing FrameLayout

size

  • Stop Preview

  • Resize Preview

    and FrameLyout

    resize

  • Start Preview

    again.

I did it successfully, but the preview is darker than the previous preview. Please let me know what is the reason.

Should I reopen the camera before resizing FrameLayout

?

+3


source to share


3 answers


Starting a camera preview includes the following steps: -

1. Get a camera instance:
 Camera camera = Camera.open(cameraId)


2. Paint a surface on this camera instance that will be used to display the preview with camera.setPreviewDisplay(SurfaceHolder)

3. Set some parameters if you need, for example Camera.Parameters params = camera.getParameters();


params.setFlashMode(String)

,
params.setPreviewSize(int , int)


camera.setParameters(params)

4. Start previewing the camera by calling: - camera.startPreview



That's all you need to do to start the camera preview.

As per your requirement, when you want to resize the surface and preview, please do the following: -
a) Stop preview: - camera.stopPreview()


b) Repeat steps 2-4 as above.

Closing the camera may not be necessary unless you are switching from Back / Front or vice versa.

+2


source


You can try to copy whatever you did to start the preview and put it in the FrameLayout when you expand your code, make changes to the preview and FrameLayout, and call the new method when you want to make changes. This way everything should look the same as you completely restart the preview.



0


source


You don't even need to stop viewing here; SurfaceView automatically scales the camera output to its size, so as long as you maintain the same aspect ratio, you can easily resize the frame layout.

If you change the aspect ratio, you need to at least stop the preview, resize the preview to the appropriate aspect ratio using Camera.Parameters.setPreviewSize, and then start the preview again.

Can stopping and starting a preview without changing the layout change the brightness of the preview? If so, it sounds like a bug in the specific camera implementation.

0


source







All Articles