Tag Archives: Camera API

Video Part 1: How to use android Camera 2 API’s – Look & Feel

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.

Video Part 2: How to use android camera2 API’s -Setting preview surface width & height

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.

API’s covered:
– CameraManager
– CameraManager.getSystemService
– CameraManager.getCameraIdList
– CameraManager.getCameraCharacteristics
– CameraCharacteristics.get
– StreamConfigurationMap

Video Part 3: Android camera2 API – How to open CameraDevice

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.

API’s covered:
– CameraManager
– CameraManager.getSystemService
– CameraManager.openCamera
– CameraDevice
– CameraDevice.StateCallback

Video Part 4: Android camera2 API – Starting surface preview session

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.

API’s covered:
– SurfaceTexture
– SurfaceTexture.setDefaultBufferSize
– Surface
– CaptureRequest.Builder
– CaptureRequest.Builder.build
– CaptureRequest.addTarget
– CameraDevice
– CameraDevice.createCaptureRequest
– CameraCaptureSession.StateCallback
– CameraCaptureSession.setRepeatingRequest
– CameraCaptureSession.StateCallback onConfigured
– CameraCaptureSession.StateCallback onConfigureFailed

Video Part 5: Android camera2 API – Setting up background thread handler

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.