ImageCapture

public final class ImageCapture
extends UseCase

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


A use case for taking a picture.

This class is designed for basic picture taking. It provides takePicture() functions to take a picture to memory or save to a file, and provides image metadata. Pictures are taken in automatic mode after focus has converged. The flash mode can additionally be set by the application.

TakePicture returns immediately and a listener is called to provide the results after the capture completes. Multiple calls to takePicture will take pictures sequentially starting after the previous picture is captured.

Note that focus and exposure metering regions can be controlled via Preview.

When capturing to memory, the captured image is made available through an ImageProxy via an ImageCapture.OnImageCapturedCallback.

Summary

Nested classes

class ImageCapture.Builder

Builder for an ImageCapture

class ImageCapture.Metadata

Holder class for metadata that will be saved with captured images. 

class ImageCapture.OnImageCapturedCallback

Callback for when an image capture has completed. 

interface ImageCapture.OnImageSavedCallback

Listener containing callbacks for image file I/O events. 

class ImageCapture.OutputFileOptions

Options for saving newly captured image. 

class ImageCapture.OutputFileResults

Info about the saved image file. 

Constants

int CAPTURE_MODE_MAXIMIZE_QUALITY

Optimizes capture pipeline to prioritize image quality over latency.

int CAPTURE_MODE_MINIMIZE_LATENCY

Optimizes capture pipeline to prioritize latency over image quality.

int ERROR_CAMERA_CLOSED

An error indicating the request cannot be done due to camera is closed.

int ERROR_CAPTURE_FAILED

An error reported by camera framework indicating the capture request is failed.

int ERROR_FILE_IO

An error occurred while attempting to read or write a file, such as when saving an image to a File.

int ERROR_INVALID_CAMERA

An error indicating this ImageCapture is not bound to a valid camera.

int ERROR_UNKNOWN

An unknown error occurred.

int FLASH_MODE_AUTO

int FLASH_MODE_OFF

No flash.

int FLASH_MODE_ON

Always flash.

Public methods

int getCaptureMode()

Returns the set capture mode.

int getFlashMode()

Get the flash mode.

ResolutionInfo getResolutionInfo()

Gets selected resolution information of the ImageCapture.

int getTargetRotation()

Returns the desired rotation of the output image.

void setCropAspectRatio(Rational aspectRatio)

Sets target cropping aspect ratio for output image.

void setFlashMode(int flashMode)

Set the flash mode.

void setTargetRotation(int rotation)

Sets the desired rotation of the output image.

void takePicture(Executor executor, ImageCapture.OnImageCapturedCallback callback)

Captures a new still image for in memory access.

void takePicture(ImageCapture.OutputFileOptions outputFileOptions, Executor executor, ImageCapture.OnImageSavedCallback imageSavedCallback)

Captures a new still image and saves to a file along with application specified metadata.

String toString()

Inherited methods

Constants

CAPTURE_MODE_MAXIMIZE_QUALITY

public static final int CAPTURE_MODE_MAXIMIZE_QUALITY

Optimizes capture pipeline to prioritize image quality over latency. When the capture mode is set to MAX_QUALITY, images may take longer to capture.

Constant Value: 0 (0x00000000)

CAPTURE_MODE_MINIMIZE_LATENCY

public static final int CAPTURE_MODE_MINIMIZE_LATENCY

Optimizes capture pipeline to prioritize latency over image quality. When the capture mode is set to MIN_LATENCY, images may capture faster but the image quality may be reduced.

Constant Value: 1 (0x00000001)

ERROR_CAMERA_CLOSED

public static final int ERROR_CAMERA_CLOSED

An error indicating the request cannot be done due to camera is closed.

Constant Value: 3 (0x00000003)

ERROR_CAPTURE_FAILED

public static final int ERROR_CAPTURE_FAILED

An error reported by camera framework indicating the capture request is failed.

Constant