ImageCapture.OnImageCapturedCallback

public abstract class ImageCapture.OnImageCapturedCallback


Callback for image capture events.

Summary

Public constructors

Public methods

void

Callback to report the progress of the capture's processing.

void

Callback for when the camera has started exposing a frame.

void

Callback for when the image has been captured.

void

Callback for when an error occurred during image capture.

void

Callback to notify that the postview bitmap is available.

Public constructors

OnImageCapturedCallback

Added in 1.0.0
public OnImageCapturedCallback()

Public methods

onCaptureProcessProgressed

Added in 1.4.0-alpha04
public void onCaptureProcessProgressed(int progress)

Callback to report the progress of the capture's processing.

To know in advanced if this callback will be invoked or not, check the capabilities by getImageCaptureCapabilities and isCaptureProcessProgressSupported. If supported, this callback will be called multiple times with monotonically increasing values. At the minimum the callback will be called once with value 100 to indicate the processing is finished. This callback will always be called before onCaptureSuccess.

Parameters
int progress

the progress ranging from 0 to 100.

onCaptureStarted

Added in 1.4.0-alpha04
public void onCaptureStarted()

Callback for when the camera has started exposing a frame.

This callback is guaranteed to be called once and before onCaptureSuccess for the same invocation of takePicture.

It's recommended to play shutter sound or trigger UI indicators of capture when receiving this callback.

onCaptureSuccess

Added in 1.0.0
public void onCaptureSuccess(@NonNull ImageProxy image)

Callback for when the image has been captured.

The application is responsible for calling close to close the image.

The image is of format JPEG, queryable via getFormat.

The image is provided as captured by the underlying ImageReader without rotation applied. The value in image.getImageInfo().getRotationDegrees() describes the magnitude of clockwise rotation, which if applied to the image will make it match the currently configured target rotation.

For example, if the current target rotation is set to the display rotation, rotationDegrees is the rotation to apply to the image to match the display orientation. A rotation of 90 degrees would mean rotating the image 90 degrees clockwise produces an image that will match the display orientation.

See also setTargetRotation and setTargetRotation.

Timestamps are in nanoseconds and monotonic and can be compared to timestamps from images produced from UseCases bound to the same camera instance. More detail is available depending on the implementation. For example with CameraX using a androidx.camera.camera2 implementation additional detail can be found in android.hardware.camera2.CameraDevice documentation.

Parameters
@NonNull ImageProxy image

The captured image

onError

Added in 1.0.0
public void onError(@NonNull ImageCaptureException exception)

Callback for when an error occurred during image capture.

Parameters
@NonNull ImageCaptureException exception

An ImageCaptureException that contains the type of error, the error message and the throwable that caused it.

onPostviewBitmapAvailable

Added in 1.4.0-alpha04
public void onPostviewBitmapAvailable(@NonNull Bitmap bitmap)

Callback to notify that the postview bitmap is available. The postview is intended to be shown on UI before the long-processing capture is completed in order to provide a better UX.

The postview is only available when the isPostviewSupported returns true for the specified CameraInfo and applications must explicitly enable the postview using the setPostviewEnabled. This callback will be called before onCaptureSuccess. But if something goes wrong when processing the postview, this callback method could be skipped.

The bitmap is rotated according to the target rotation set to the ImageCapture to make it upright. If target rotation is not set, the display rotation is used.

See also setTargetRotation and setTargetRotation.

Parameters
@NonNull Bitmap bitmap

the postview bitmap.