ImageCapture.Builder
class ImageCapture.Builder : ExtendableBuilder
Builder for an ImageCapture.
Summary
Public constructors |
|---|
Builder()Creates a new Builder object. |
Public functions |
|
|---|---|
ImageCapture |
build()Builds an immutable |
ImageCapture.Builder |
setCaptureMode(captureMode: Int)Sets the image capture mode. |
ImageCapture.Builder |
setFlashMode(flashMode: Int)Sets the flashMode. |
ImageCapture.Builder |
setIoExecutor(executor: Executor)Sets the default executor that will be used for IO tasks. |
ImageCapture.Builder |
setJpegQuality(jpegQuality: @IntRange(from = 1, to = 100) Int)Sets the output JPEG image compression quality. |
ImageCapture.Builder |
setOutputFormat(outputFormat: Int)Sets the output format of the captured image. |
ImageCapture.Builder |
setPostviewEnabled(postviewEnabled: Boolean)Enables postview image generation. |
ImageCapture.Builder |
setPostviewResolutionSelector(resolutionSelector: ResolutionSelector)Set the |
ImageCapture.Builder |
setResolutionSelector(resolutionSelector: ResolutionSelector)Sets the resolution selector to select the preferred supported resolution. |
ImageCapture.Builder |
setScreenFlash(screenFlash: ImageCapture.ScreenFlash)Sets the |
ImageCapture.Builder |
This function is deprecated. use |
ImageCapture.Builder |
setTargetName(targetName: String)Sets the name of the target object being configured, used only for debug logging. |
ImageCapture.Builder |
This function is deprecated. use |
ImageCapture.Builder |
setTargetRotation(rotation: Int)Sets the rotation of the intended target for images from this configuration. |
Public functions
build
fun build(): ImageCapture
Builds an immutable ImageCapture from the current state.
| Returns | |
|---|---|
ImageCapture |
A |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if attempting to set both target aspect ratio and target resolution, or attempting to set |
setCaptureMode
fun setCaptureMode(captureMode: Int): ImageCapture.Builder
Sets the image capture mode.
Valid capture modes are CAPTURE_MODE_MINIMIZE_LATENCY, which prioritizes latency over image quality, or CAPTURE_MODE_MAXIMIZE_QUALITY, which prioritizes image quality over latency.
If not set, the capture mode will default to CAPTURE_MODE_MINIMIZE_LATENCY.
| Parameters | |
|---|---|
captureMode: Int |
The requested image capture mode. |
| Returns | |
|---|---|
ImageCapture.Builder |
The current Builder. |
setFlashMode
fun setFlashMode(flashMode: Int): ImageCapture.Builder
Sets the flashMode.
If not set, the flash mode will default to FLASH_MODE_OFF.
If set to FLASH_MODE_SCREEN, a non-null ScreenFlash instance must also be set with setScreenFlash. Otherwise, an IllegalArgumentException will be thrown when build is invoked.
See setFlashMode for more information.
| Parameters | |
|---|---|
flashMode: Int |
The requested flash mode. Value is |
| Returns | |
|---|---|
ImageCapture.Builder |
The current Builder. |
setIoExecutor
fun setIoExecutor(executor: Executor): ImageCapture.Builder
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 takePicture. 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. |
setJpegQuality
fun setJpegQuality(jpegQuality: @IntRange(from = 1, to = 100) Int): ImageCapture.Builder
Sets the output JPEG image compression quality.
This is used for the ImageProxy which is returned by takePicture or the output JPEG image which is saved by takePicture. The saved JPEG image might be cropped according to the ViewPort setting or the crop aspect ratio set by setCropAspectRatio. 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 CAPTURE_MODE_MINIMIZE_LATENCY and 100 is used for CAPTURE_MODE_MAXIMIZE_QUALITY.
| Parameters | |
|---|---|
jpegQuality: @IntRange(from = 1, to = 100) Int |
The requested output JPEG image compression quality. The value must be in range [1..100] which larger is higher quality. |
| Returns | |
|---|---|
ImageCapture.Builder |
The current Builder. |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if the input value is not in range [1..100]. |
setOutputFormat
fun setOutputFormat(outputFormat: Int): ImageCapture.Builder
Sets the output format of the captured image.
The supported output formats for capturing image depend on the capabilities of the camera. The supported output formats of the camera can be queried using getSupportedOutputFormats.
If not set, the output format will default to OUTPUT_FORMAT_JPEG.
An IllegalArgumentException will be thrown when binding the UseCase if the specified output format is not supported. Please note that the supported output formats might be changed when Extensions is enabled.
| Parameters | |
|---|---|
outputFormat: Int |
The output image format. Value is |
| Returns | |
|---|---|
ImageCapture.Builder |
The current Builder. |
setPostviewEnabled
fun setPostviewEnabled(postviewEnabled: Boolean): ImageCapture.Builder
Enables postview image generation. A postview image is a low-quality image that's produced earlier during image capture than the final high-quality image, and can be used as a thumbnail or placeholder until the final image is ready.
When the postview is available, onPostviewBitmapAvailable or onPostviewBitmapAvailable will be called.
By default the largest available postview size that is smaller or equal to the ImagaeCapture size will be used to configure the postview. The ResolutionSelector can also be used to select a specific size via setPostviewResolutionSelector.
You can query the postview capability by invoking getImageCaptureCapabilities. If isPostviewSupported returns false and you still enable the postview, the postview image won't be generated.
| Parameters | |
|---|---|
postviewEnabled: Boolean |
whether postview is enabled or not |
| Returns | |
|---|---|
ImageCapture.Builder |
the current Builder. |
setPostviewResolutionSelector
fun setPostviewResolutionSelector(resolutionSelector: ResolutionSelector): ImageCapture.Builder
Set the ResolutionSelector to select the postview size from the available postview sizes. These available postview sizes are smaller or equal to the ImageCapture size. You can implement the androidx.camera.core.resolutionselector.ResolutionFilter and set it to the ResolutionSelector to get the list of available sizes and determine which size to use.
If no sizes can be selected using the given ResolutionSelector, it will throw an IllegalArgumentException when bindToLifecycle() is invoked.
| Returns | |
|---|---|
ImageCapture.Builder |
the current Builder. |
setResolutionSelector
fun setResolutionSelector(resolutionSelector: ResolutionSelector): ImageCapture.Builder
Sets the resolution selector to select the preferred supported resolution.
The default resolution strategy for ImageCapture is HIGHEST_AVAILABLE_STRATEGY, which will select the largest available resolution to use. Applications can override this default strategy with a different resolution strategy.
The existing setTargetResolution and setTargetAspectRatio APIs are deprecated and are not compatible with setResolutionSelector. Calling either of these APIs together with setResolutionSelector will result in an IllegalArgumentException being thrown when you attempt to build the ImageCapture instance.
| Returns | |
|---|---|
ImageCapture.Builder |
The current Builder. |
setScreenFlash
fun setScreenFlash(screenFlash: ImageCapture.ScreenFlash): ImageCapture.Builder
Sets the ScreenFlash instance necessary for screen flash operations.
If not set, the instance will be set to null and users will need to set it later before calling setFlashMode with FLASH_MODE_SCREEN.
See setScreenFlash for more information.
| Parameters | |
|---|---|
screenFlash: ImageCapture.ScreenFlash |
The |
| Returns | |
|---|---|
ImageCapture.Builder |
The current Builder. |
funsetTargetAspectRatio(aspectRatio: Int): ImageCapture.Builder
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, or RATIO_DEFAULT is supplied, resolutions with aspect ratio 4:3 will be considered in higher priority.
| Parameters | |
|---|---|
aspectRatio: Int |
The desired ImageCapture |
| Returns | |
|---|---|
ImageCapture.Builder |
The current Builder. |
setTargetName
fun setTargetName(targetName: String): ImageCapture.Builder
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: String |
A unique string identifier for the instance of the class being configured. |
| Returns | |
|---|---|
ImageCapture.Builder |
the current Builder. |
funsetTargetResolution(resolution: Size): ImageCapture.Builder
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 Size 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 Size 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, setCropAspectRatio 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 href="https://developer.android.com/reference/android/hardware/camera2/CameraDevice #regular-capture">Regular capture section.
| Parameters | |
|---|---|
resolution: Size |
The target resolution to choose from supported output sizes list. |
| Returns | |
|---|---|
ImageCapture.Builder |
The current Builder. |
setTargetRotation
fun setTargetRotation(rotation: Int): ImageCapture.Builder
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 getRotationDegrees value of the ImageProxy returned by 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_0, ROTATION_90, ROTATION_180, ROTATION_270. Rotation values are relative to the "natural" rotation, ROTATION_0.
In general, it is best to additionally set the target rotation dynamically on the use case. See setTargetRotation for additional documentation.
If not set, the target rotation will default to the value of getRotation 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: Int |
The rotation of the intended target. |
| Returns | |
|---|---|
ImageCapture.Builder |
The current Builder. |