CameraProvider

class CameraProvider(cameraInstance: CameraInstance)

A class that provides Camera2 API features to any class that implements the CameraInstance interface.

Constructors

CameraProvider
Link copied to clipboard
fun CameraProvider(cameraInstance: CameraInstance)

Types

OPTIONS
Link copied to clipboard
object OPTIONS

Options for the camera image.

Functions

captureImageWithPreviewExtraction
Link copied to clipboard
fun captureImageWithPreviewExtraction(): Bitmap?

Captures the current frame of the previewTextureView and returns it as a Bitmap.

chooseOptimalSize
Link copied to clipboard
private fun chooseOptimalSize(choices: Array<Size>, textureViewWidth: Int, textureViewHeight: Int, maxWidth: Int, maxHeight: Int, aspectRatio: Size): Size?

Helper method for choosing a Size of a given set of choices, which best fits the given constraints.

createCameraCaptureSession
Link copied to clipboard
private fun createCameraCaptureSession()
initializeTextureView
Link copied to clipboard
private fun initializeTextureView()

Initializes previewTextureView and sets the SurfaceTextureListener.

openCamera
Link copied to clipboard
fun openCamera(width: Int, height: Int)

Opens the camera with the provided width and height if Manifest.permission.CAMERA is granted.

pause
Link copied to clipboard
fun pause()
setUpCameraOutputs
Link copied to clipboard
private fun setUpCameraOutputs(width: Int, height: Int)

Sets up the camera output by choosing the optimal size from all available cameras.

start
Link copied to clipboard
fun start()

Starts the camera preview on previewTextureView.

stop
Link copied to clipboard
fun stop()

Properties

ca
Link copied to clipboard
private var ca: Activity?
cameraCaptureSessionStateCallback
Link copied to clipboard

Callback for handling all state changes of captureSession.

cameraDevice
Link copied to clipboard
private var cameraDevice: CameraDevice? = null

The open camera

cameraDeviceStateCallback
Link copied to clipboard
private var cameraDeviceStateCallback: CameraDevice.StateCallback?

Callback for handling all state changes of the open camera.

cameraId
Link copied to clipboard
private lateinit var cameraId: String

The physical camera id

cameraOpenCloseLock
Link copied to clipboard
private var cameraOpenCloseLock: Semaphore

Prevents closing the app without closing the camera first

captureSession
Link copied to clipboard
private var captureSession: CameraCaptureSession? = null

The active camera capture session

ci
Link copied to clipboard
private var ci: CameraInstance?

The CameraInstance passed through the constructor

imageReader
Link copied to clipboard
private var imageReader: ImageReader? = null

Handler for still image capture

previewRequest
Link copied to clipboard
private lateinit var previewRequest: CaptureRequest

The CaptureRequest to get camera images for the preview

previewRequestBuilder
Link copied to clipboard
private lateinit var previewRequestBuilder: CaptureRequest.Builder

The builder for previewRequest

previewSize
Link copied to clipboard
private lateinit var previewSize: Size

The Size of the camera preview image

previewTextureView
Link copied to clipboard
private var previewTextureView: TextureView? = null

The TextureView, on which the camera preview image will be displayed

surfaceTexture
Link copied to clipboard
private var surfaceTexture: SurfaceTexture? = null