The first part of the android tutorial focuses on the image gallery part of the android application. Which is making the image gallery horizontal instead of vertical and moving the gallery to the top of the android application.
At the end a TextureView will be added to the main layout which will be used as the preview surface for the android camera 2 api’s.
First of all the width & height of the TextureView in the xml layout has to be calculated.
A simple way of working this out is to create a SurfaceTextureListener whose onSurfaceTextureAvailable callback will provide the TextureView width & height.
Once we have these dimensions we then have to get the CameraCharacteristics of the particular camera we want to use and get the output sizes that will support the preview surface.
Once we find a close match for our requested TextureView width & height we will save those values. At this stage we will also have found the cameraId we will be using and that will also be saved to a member.
After the android surface preview sizes have been calculated the next step will be to create CameraDevice & CameraDevice.StateCallback methods.
And then to open the camera using the CameraManager with the cameraId and statecallback arguments.
If the CameraDevice is successfully opened the statecallback method onOpened will be called providing a configured CameraDevice as an argument.
This android tutorial focuses on completing the setup for the camera2 surface preview session.
The first step is to create a camera2 surface based on the TextureView.
Then create a CaptureRequestBuilder using the CameraDevice and add the camera2 surface to the CaptureRequestBuilder.
Next use the CameraDevice to create a CameraCaptureSession and include the surface preview and capture session StateCallback as arguments.
In the CameraCaptureSession’s onConfigured method setup the CaptureRequest, initialise the CameraCaptureSession member and then call the CameraCaptureSession’s setRepeatingRequest method.
It also pays to setup a toast in the CameraCaptureSession’s onConfigureFailed in case something has gone wrong.
– CameraCaptureSession.StateCallback onConfigured
– CameraCaptureSession.StateCallback onConfigureFailed
Part 5 of the camera2 API tutorial series which concentrates on creating the background thread handler for the android camera2 api sessions & callbacks as well as closing resources when the application is closed.