ImageCapture.Builder

public static final class ImageCapture.Builder
extends Object implements ExtendableBuilder<T extends UseCase>

java.lang.Object
   ↳ androidx.camera.core.ImageCapture.Builder


Builder for an ImageCapture.

Summary

Public constructors

Builder()

Creates a new Builder object.

Public methods

ImageCapture build()

Builds an immutable ImageCapture from the current state.

ImageCapture.Builder setCaptureMode(int captureMode)

Sets the image capture mode.

ImageCapture.Builder setFlashMode(int flashMode)

Sets the flashMode.

ImageCapture.Builder setIoExecutor(Executor executor)

Sets the default executor that will be used for IO tasks.

ImageCapture.Builder setTargetAspectRatio(int aspectRatio)

Sets the aspect ratio of the intended target for images from this configuration.

ImageCapture.Builder setTargetName(String targetName)

Sets the name of the target object being configured, used only for debug logging.

ImageCapture.Builder setTargetResolution(Size resolution)

Sets the intended output target resolution.

ImageCapture.Builder setTargetRotation(int rotation)

Sets the rotation of the intended target for images from this configuration.

Inherited methods

Public constructors

Builder

public Builder ()

Creates a new Builder object.

Public methods

build

public ImageCapture build ()

Builds an immutable ImageCapture from the current state.

Returns
ImageCapture A ImageCapture populated with the current state.

Throws
IllegalArgumentException if attempting to set both target aspect ratio and target resolution.

setCaptureMode

public ImageCapture.Builder setCaptureMode (int captureMode)

Sets the image capture mode.

Valid capture modes are ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY, which prioritizes latency over image quality, or ImageCapture.CAPTURE_MODE_MAXIMIZE_QUALITY, which prioritizes image quality over latency.

If not set, the capture mode will default to ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY.

Parameters
captureMode int: The requested image capture mode.

Returns
ImageCapture.Builder The current Builder.

setFlashMode

public ImageCapture.Builder setFlashMode (int flashMode)

Sets the flashMode.

If not set, the flash mode will default to ImageCapture.FLASH_MODE_OFF.

See ImageCapture.setFlashMode(int) for more information.

Parameters
flashMode int: The requested flash mode. Value is ImageCapture.FLASH_MODE_AUTO, ImageCapture.FLASH_MODE_ON, or ImageCapture.FLASH_MODE_OFF.

Returns
ImageCapture.Builder The current Builder.

setIoExecutor

public ImageCapture.Builder setIoExecutor (Executor executor)

Sets the default executor that will be used for IO tasks.

This executor will be used for any IO tasks specifically for ImageCapture, such as ImageCapture.takePicture(OutputFileOptions, Executor, ImageCapture.OnImageSavedCallback). If no executor is set, then a default Executor specifically for IO will be used instead.

Parameters
executor Executor: The executor which will be used for IO tasks.

Returns
ImageCapture.Builder the current Builder.

setTargetAspectRatio

public ImageCapture.Builder setTargetAspectRatio (int aspectRatio)

Sets the aspect ratio of the intended target for images from this configuration.

The aspect ratio is the ratio of width to height in the sensor orientation.

It is not allowed to set both target aspect ratio and target resolution on the same use case. Attempting so will throw an IllegalArgumentException when building the Config.

The target aspect ratio is used as a hint when determining the resulting output aspect ratio which may differ from the request, possibly due to device constraints. Application code should check the resulting output's resolution and the resulting aspect ratio may not be exactly as requested.

If not set, resolutions with aspect ratio 4:3 will be considered in higher priority.

Parameters
aspectRatio int: The desired ImageCapture AspectRatio

Returns
ImageCapture.Builder The current Builder.