Added in API level 21

CaptureRequest.Builder


public static final class CaptureRequest.Builder
extends Object

java.lang.Object
   ↳ android.hardware.camera2.CaptureRequest.Builder


A builder for capture requests.

To obtain a builder instance, use the CameraDevice#createCaptureRequest or CameraDevice.CameraDeviceSetup#createCaptureRequest method, which initializes the request fields to one of the templates defined in CameraDevice.

Summary

Public methods

void addTarget(Surface outputTarget)

Add a surface to the list of targets for this request

The Surface added must be one of the surfaces included in the most recent call to CameraDevice#createCaptureSession, when the request is given to the camera device.

CaptureRequest build()

Build a request using the current target Surfaces and settings.

<T> T get(Key<T> key)

Get a capture request field value.

<T> T getPhysicalCameraKey(Key<T> key, String physicalCameraId)

Get a capture request field value for a specific physical camera Id.

void removeTarget(Surface outputTarget)

Remove a surface from the list of targets for this request.

<T> void set(Key<T> key, T value)

Set a capture request field to a value.

<T> CaptureRequest.Builder setPhysicalCameraKey(Key<T> key, T value, String physicalCameraId)

Set a capture request field to a value.

void setTag(Object tag)

Set a tag for this request.

Inherited methods

Public methods

addTarget

Added in API level 21
public void addTarget (Surface outputTarget)

Add a surface to the list of targets for this request

The Surface added must be one of the surfaces included in the most recent call to CameraDevice#createCaptureSession, when the request is given to the camera device.

Adding a target more than once has no effect.

Parameters
outputTarget Surface: Surface to use as an output target for this request This value cannot be null.

build

Added in API level 21
public CaptureRequest build ()

Build a request using the current target Surfaces and settings.

Note that, although it is possible to create a CaptureRequest with no target Surfaces, passing such a request into CameraCaptureSession#capture, CameraCaptureSession#captureBurst, CameraCaptureSession#setRepeatingBurst, or CameraCaptureSession#setRepeatingRequest will cause that method to throw an IllegalArgumentException.

Returns
CaptureRequest A new capture request instance, ready for submission to the camera device. This value cannot be null.

get

Added in API level 21
public T get (Key<T> key)

Get a capture request field value. The field definitions can be found in CaptureRequest.

Parameters
key Key: The metadata field to read.

Returns
T The value of that key, or null if the field is not set.

Throws
IllegalArgumentException if the key was not valid

getPhysicalCameraKey

Added in API level 28
public T getPhysicalCameraKey (Key<T> key, 
                String physicalCameraId)

Get a capture request field value for a specific physical camera Id. The field definitions can be found in CaptureRequest.

This method can be called for logical camera devices, which are devices that have REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA capability and calls to CameraCharacteristics#getPhysicalCameraIds return a non-empty list of physical devices that are backing the logical camera. The camera Id included in the 'physicalCameraId' argument selects an individual physical device and returns its specific capture request field.

Parameters
key Key: The metadata field to read.

physicalCameraId String: A valid physical camera Id. The valid camera Ids can be obtained via calls to CameraCharacteristics#getPhysicalCameraIds. This value cannot be null.

Returns
T The value of that key, or null if the field is not set.

Throws
IllegalArgumentException if the key or physical camera id were not valid

removeTarget

Added in API level 21
public void removeTarget (Surface outputTarget)

Remove a surface from the list of targets for this request.

Removing a target that is not currently added has no effect.

Parameters
outputTarget Surface: Surface to use as an output target for this request This value cannot be null.

set

Added in API level 21
public void set (Key<T> key, 
                T value)

Set a capture request field to a value. The field definitions can be found in CaptureRequest.

Setting a field to null will remove that field from the capture request. Unless the field is optional, removing it will likely produce an error from the camera device when the request is submitted.

Parameters
key Key: The metadata field to write. This value cannot be null.

value T: The value to set the field to, which must be of a matching type to the key.

setPhysicalCameraKey

Added in API level 28
public CaptureRequest.Builder setPhysicalCameraKey (Key<T> key, 
                T value, 
                String physicalCameraId)

Set a capture request field to a value. The field definitions can be found in CaptureRequest.

Setting a field to null will remove that field from the capture request. Unless the field is optional, removing it will likely produce an error from the camera device when the request is submitted.

This method can be called for logical camera devices, which are devices that have REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA capability and calls to CameraCharacteristics#getPhysicalCameraIds return a non-empty set of physical devices that are backing the logical camera. The camera Id included in the 'physicalCameraId' argument selects an individual physical device that will receive the customized capture request field.

Parameters
key Key: The metadata field to write. This value cannot be null.

value T: The value to set the field to, which must be of a matching type to the key.

physicalCameraId String: A valid physical camera Id. The valid camera Ids can be obtained via calls to CameraCharacteristics#getPhysicalCameraIds. This value cannot be null.

Returns
CaptureRequest.Builder The builder object.

Throws
IllegalArgumentException if the physical camera id is not valid

setTag

Added in API level 21
public void setTag (Object tag)

Set a tag for this request.

This tag is not used for anything by the camera device, but can be used by an application to easily identify a CaptureRequest when it is returned by CaptureCallback.onCaptureCompleted.

If the application overrides the tag object's Object#toString function, the returned string must not contain personal identifiable information.

Parameters
tag Object: an arbitrary Object to store with this request This value may be null.