Stay organized with collections Save and categorize content based on your preferences.

Camera2CameraControl

@ExperimentalCamera2Interop
@RequiresApi(value = 21)
public final class Camera2CameraControl


An class that provides ability to interoperate with the android.hardware.camera2 APIs.

Camera2 specific controls, like capture request options, can be applied through this class. A Camera2CameraControl can be created from a general CameraControl which is associated to a camera. Then the controls will affect all use cases that are using that camera.

If any option applied by Camera2CameraControl conflicts with the options required by CameraX internally. The options from Camera2CameraControl will override, which may result in unexpected behavior depends on the options being applied.

Summary

Public methods

@NonNull ListenableFuture<Void>

Adds a CaptureRequestOptions updates the session with the options it contains.

@NonNull ListenableFuture<Void>

Clears all capture request options that is currently applied by the Camera2CameraControl.

static @NonNull Camera2CameraControl
from(@NonNull CameraControl cameraControl)

Gets the Camera2CameraControl from a CameraControl.

@NonNull CaptureRequestOptions

Gets all the capture request options that is currently applied by the Camera2CameraControl.

@NonNull ListenableFuture<Void>

Sets a CaptureRequestOptions and updates the session with the options it contains.

Public methods

addCaptureRequestOptions

public @NonNull ListenableFuture<VoidaddCaptureRequestOptions(@NonNull CaptureRequestOptions bundle)

Adds a CaptureRequestOptions updates the session with the options it contains.

The options will be merged with the existing options. If one option is set with a different value, it will overwrite the existing value.

Any values which are in conflict with values already set by CameraX, such as by androidx.camera.core.CameraControl, will overwrite the existing values. The values will be submitted with every repeating and single capture requests issued by CameraX, which may result in unexpected behavior depends on the values being applied.

Parameters
@NonNull CaptureRequestOptions bundle

The CaptureRequestOptions which will be set.

Returns
@NonNull ListenableFuture<Void>

a ListenableFuture which completes when the repeating android.hardware.camera2.CaptureResult shows the options have be submitted completely. The future fails with CameraControl.OperationCanceledException if newer options are set or camera is closed before the current request completes.

clearCaptureRequestOptions

public @NonNull ListenableFuture<VoidclearCaptureRequestOptions()

Clears all capture request options that is currently applied by the Camera2CameraControl.

Returns
@NonNull ListenableFuture<Void>

a ListenableFuture which completes when the repeating android.hardware.camera2.CaptureResult shows the options have be submitted completely. The future fails with CameraControl.OperationCanceledException if newer options are set or camera is closed before the current request completes.

from

public static @NonNull Camera2CameraControl from(@NonNull CameraControl cameraControl)

Gets the Camera2CameraControl from a CameraControl.

The CameraControl is still usable after a Camera2CameraControl is obtained from it. Note that the Camera2CameraControl has higher priority than the CameraControl. For example, if FLASH_MODE is set through the Camera2CameraControl. All CameraControl features that required FLASH_MODE internally like torch may not work properly.

Parameters
@NonNull CameraControl cameraControl

The CameraControl to get from.

Returns
@NonNull Camera2CameraControl

The camera control with Camera2 implementation.

Throws
java.lang.IllegalArgumentException java.lang.IllegalArgumentException

if the camera control does not contain the camera2 information (e.g., if CameraX was not initialized with a androidx.camera.camera2.Camera2Config).

getCaptureRequestOptions

public @NonNull CaptureRequestOptions getCaptureRequestOptions()

Gets all the capture request options that is currently applied by the Camera2CameraControl.

It doesn't include the capture request options applied by the android.hardware.camera2.CameraDevice templates or by CameraX.

setCaptureRequestOptions

public @NonNull ListenableFuture<VoidsetCaptureRequestOptions(@NonNull CaptureRequestOptions bundle)

Sets a CaptureRequestOptions and updates the session with the options it contains.

This will first clear all options that have already been set, then apply the new options.

Any values which are in conflict with values already set by CameraX, such as by androidx.camera.core.CameraControl, will overwrite the existing values. The values will be submitted with every repeating and single capture requests issued by CameraX, which may result in unexpected behavior depending on the values being applied.

Parameters
@NonNull CaptureRequestOptions bundle

The CaptureRequestOptions which will be set.

Returns
@NonNull ListenableFuture<Void>

a ListenableFuture which completes when the repeating android.hardware.camera2.CaptureResult shows the options have be submitted completely. The future fails with CameraControl.OperationCanceledException if newer options are set or camera is closed before the current request completes. Cancelling the ListenableFuture is a no-op.