public final class

ImageCapture.Builder

extends java.lang.Object

implements UseCaseConfig.Builder<ImageCapture, ImageCaptureConfig, ImageCapture.Builder>, ImageOutputConfig.Builder<ImageCapture.Builder>, IoConfig.Builder<ImageCapture.Builder>

 java.lang.Object

↳androidx.camera.core.ImageCapture.Builder

Overview

Builder for an ImageCapture.

Summary

Constructors
publicBuilder()

Creates a new Builder object.

Methods
public ImageCapturebuild()

Builds an immutable ImageCapture from the current state.

public static ImageCapture.BuilderfromConfig(Config configuration)

Generates a Builder from another Config object

public MutableConfiggetMutableConfig()

public ImageCaptureConfiggetUseCaseConfig()

public ImageCapture.BuildersetBufferFormat(int bufferImageFormat)

Sets the of the ImageProxy returned by the ImageCapture.OnImageCapturedCallback.

public ImageCapture.BuildersetCameraSelector(CameraSelector cameraSelector)

public ImageCapture.BuildersetCaptureBundle(CaptureBundle captureBundle)

Sets the CaptureBundle.

public ImageCapture.BuildersetCaptureMode(int captureMode)

Sets the image capture mode.

public ImageCapture.BuildersetCaptureOptionUnpacker(CaptureConfig.OptionUnpacker optionUnpacker)

public ImageCapture.BuildersetCaptureProcessor(CaptureProcessor captureProcessor)

Sets the CaptureProcessor.

public ImageCapture.BuildersetDefaultCaptureConfig(CaptureConfig captureConfig)

public ImageCapture.BuildersetDefaultResolution(Size resolution)

Sets the default resolution of the intended target from this configuration.

public ImageCapture.BuildersetDefaultSessionConfig(SessionConfig sessionConfig)

public ImageCapture.BuildersetFlashMode(int flashMode)

Sets the flashMode.

public ImageCapture.BuildersetFlashType(int flashType)

Sets the flashType.

public ImageCapture.BuildersetImageReaderProxyProvider(ImageReaderProxyProvider imageReaderProxyProvider)

public ImageCapture.BuildersetIoExecutor(java.util.concurrent.Executor executor)

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

public ImageCapture.BuildersetJpegQuality(int jpegQuality)

Sets the output JPEG image compression quality.

public ImageCapture.BuildersetMaxCaptureStages(int maxCaptureStages)

Sets the max number of CaptureStage.

public ImageCapture.BuildersetMaxResolution(Size resolution)

public ImageCapture.BuildersetSessionOptionUnpacker(SessionConfig.OptionUnpacker optionUnpacker)

public ImageCapture.BuildersetSoftwareJpegEncoderRequested(boolean requestSoftwareJpeg)

public ImageCapture.BuildersetSupportedResolutions(java.util.List<> resolutions)

public ImageCapture.BuildersetSurfaceOccupancyPriority(int priority)

public ImageCapture.BuildersetTargetAspectRatio(int aspectRatio)

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

public ImageCapture.BuildersetTargetClass(java.lang.Class<ImageCapture> targetClass)

public ImageCapture.BuildersetTargetName(java.lang.String targetName)

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

public ImageCapture.BuildersetTargetResolution(Size resolution)

Sets the intended output target resolution.

public ImageCapture.BuildersetTargetRotation(int rotation)

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

public ImageCapture.BuildersetUseCaseEventCallback(UseCase.EventCallback useCaseEventCallback)

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder()

Creates a new Builder object.

Methods

public static ImageCapture.Builder fromConfig(Config configuration)

Generates a Builder from another Config object

Parameters:

configuration: An immutable configuration to pre-populate this builder.

Returns:

The new Builder.

public MutableConfig getMutableConfig()

public ImageCaptureConfig getUseCaseConfig()

public ImageCapture build()

Builds an immutable ImageCapture from the current state.

Returns:

A ImageCapture populated with the current state.

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: The requested image capture mode.

Returns:

The current Builder.

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: The requested flash mode. Value is ImageCapture.FLASH_MODE_AUTO, ImageCapture.FLASH_MODE_ON, or ImageCapture.FLASH_MODE_OFF.

Returns:

The current Builder.

public ImageCapture.Builder setCaptureBundle(CaptureBundle captureBundle)

Sets the CaptureBundle.

Parameters:

captureBundle: The requested capture bundle for extension.

Returns:

The current Builder.

public ImageCapture.Builder setCaptureProcessor(CaptureProcessor captureProcessor)

Sets the CaptureProcessor.

Parameters:

captureProcessor: The requested capture processor for extension.

Returns:

The current Builder.

public ImageCapture.Builder setBufferFormat(int bufferImageFormat)

Sets the of the ImageProxy returned by the ImageCapture.OnImageCapturedCallback.

Warning. This could lead to an invalid configuration as image format support is per device. Also, setting the buffer format in conjuncture with image capture extensions will result in an invalid configuration. In this case ImageCapture.ImageCapture(ImageCaptureConfig) will throw an java.lang.IllegalArgumentException.

Parameters:

bufferImageFormat: The image format for captured images.

Returns:

The current Builder.

public ImageCapture.Builder setMaxCaptureStages(int maxCaptureStages)

Sets the max number of CaptureStage.

Parameters:

maxCaptureStages: The max CaptureStage number.

Returns:

The current Builder.

public ImageCapture.Builder setSupportedResolutions(java.util.List<> resolutions)

public ImageCapture.Builder setTargetClass(java.lang.Class<ImageCapture> targetClass)

public ImageCapture.Builder setTargetName(java.lang.String targetName)

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

The name should be a value that can uniquely identify an instance of the object being configured.

If not set, the target name will default to a unique name automatically generated with the class canonical name and random UUID.

Parameters:

targetName: A unique string identifier for the instance of the class being configured.

Returns:

the current Builder.

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: The desired ImageCapture AspectRatio

Returns:

The current Builder.

public ImageCapture.Builder setTargetRotation(int rotation)

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

This will affect the EXIF rotation metadata in images saved by takePicture calls and the ImageInfo.getRotationDegrees() value of the ImageProxy returned by ImageCapture.OnImageCapturedCallback. These will be set to be the rotation, which if applied to the output image data, will make the image match the target rotation specified here.

This is one of four valid values: , , , . Rotation values are relative to the "natural" rotation, .

In general, it is best to additionally set the target rotation dynamically on the use case. See ImageCapture.setTargetRotation(int) for additional documentation.

If not set, the target rotation will default to the value of of the default display at the time the use case is created. The use case is fully created once it has been attached to a camera.

Parameters:

rotation: The rotation of the intended target.

Returns:

The current Builder.

See also: ImageCapture.setTargetRotation(int)

public ImageCapture.Builder setTargetResolution(Size resolution)

Sets the intended output target resolution.

The target resolution attempts to establish a minimum bound for the image resolution. The actual image resolution will be the closest available resolution in size that is not smaller than the target resolution, as determined by the Camera implementation. However, if no resolution exists that is equal to or larger than the target resolution, the nearest available resolution smaller than the target resolution will be chosen. Resolutions with the same aspect ratio of the provided will be considered in higher priority before resolutions of different aspect ratios.

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 resolution should be expressed in the coordinate frame after rotating the supported sizes by the target rotation. For example, a device with portrait natural orientation in natural target rotation requesting a portrait image may specify 480x640, and the same device, rotated 90 degrees and targeting landscape orientation may specify 640x480.

When the target resolution is set, ImageCapture.setCropAspectRatio(Rational) will be automatically called to set corresponding value. Such that the output image will be cropped into the desired aspect ratio.

The maximum available resolution that could be selected for an ImageCapture will depend on the camera device's capability.

If not set, the largest available resolution will be selected to use. Usually, users will intend to get the largest still image that the camera device can support.

When using the camera-camera2 CameraX implementation, which resolution will be finally selected will depend on the camera device's hardware level and the bound use cases combination. For more details see the guaranteed supported configurations tables in android.hardware.camera2.CameraDevice's Regular capture section.

Parameters:

resolution: The target resolution to choose from supported output sizes list.

Returns:

The current Builder.

public ImageCapture.Builder setDefaultResolution(Size resolution)

Sets the default resolution of the intended target from this configuration.

Parameters:

resolution: The default resolution to choose from supported output sizes list.

Returns:

The current Builder.

public ImageCapture.Builder setMaxResolution(Size resolution)

public ImageCapture.Builder setImageReaderProxyProvider(ImageReaderProxyProvider imageReaderProxyProvider)

public ImageCapture.Builder setSoftwareJpegEncoderRequested(boolean requestSoftwareJpeg)

public ImageCapture.Builder setFlashType(int flashType)

Sets the flashType.

If not set, the flash type will default to ImageCapture.FLASH_TYPE_ONE_SHOT_FLASH.

Parameters:

flashType: The requested flash mode. Value is ImageCapture.FLASH_TYPE_ONE_SHOT_FLASH or ImageCapture.FLASH_TYPE_USE_TORCH_AS_FLASH.

Returns:

The current Builder.

public ImageCapture.Builder setJpegQuality(int jpegQuality)

Sets the output JPEG image compression quality.

This is used for the ImageProxy which is returned by ImageCapture.takePicture(Executor, ImageCapture.OnImageCapturedCallback) or the output JPEG image which is saved by ImageCapture.takePicture(ImageCapture.OutputFileOptions, Executor, ImageCapture.OnImageSavedCallback). The saved JPEG image might be cropped according to the ViewPort setting or the crop aspect ratio set by ImageCapture.setCropAspectRatio(Rational). The JPEG quality setting will also be used to compress the cropped output image.

If not set, a default value will be used according to the capture mode setting. JPEG compression quality 95 is used for ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY and 100 is used for ImageCapture.CAPTURE_MODE_MAXIMIZE_QUALITY.

Parameters:

jpegQuality: The requested output JPEG image compression quality. The value must be in range [1..100] which larger is higher quality.

Returns:

The current Builder.

public ImageCapture.Builder setIoExecutor(java.util.concurrent.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(ImageCapture.OutputFileOptions, Executor, ImageCapture.OnImageSavedCallback). If no executor is set, then a default Executor specifically for IO will be used instead.

Parameters:

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

Returns:

the current Builder.

public ImageCapture.Builder setDefaultSessionConfig(SessionConfig sessionConfig)

public ImageCapture.Builder setDefaultCaptureConfig(CaptureConfig captureConfig)

public ImageCapture.Builder setSessionOptionUnpacker(SessionConfig.OptionUnpacker optionUnpacker)

public ImageCapture.Builder setCaptureOptionUnpacker(CaptureConfig.OptionUnpacker optionUnpacker)

public ImageCapture.Builder setCameraSelector(CameraSelector cameraSelector)

public ImageCapture.Builder setSurfaceOccupancyPriority(int priority)

public ImageCapture.Builder setUseCaseEventCallback(UseCase.EventCallback useCaseEventCallback)