ImageCapture.OnImageCapturedCallback


abstract class ImageCapture.OnImageCapturedCallback


Callback for image capture events.

Summary

Public constructors

Public functions

Unit

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

Unit

Callback for when the camera has started exposing a frame.

Unit

Callback for when the image has been captured.

Unit

Callback for when an error occurred during image capture.

Unit

Callback to notify that the postview bitmap is available.

Public constructors

OnImageCapturedCallback

Added in 1.0.0
OnImageCapturedCallback()

Public functions

onCaptureProcessProgressed

Added in 1.4.0
fun onCaptureProcessProgressed(progress: Int): Unit

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
progress: Int

the progress ranging from 0 to 100.

onCaptureStarted

Added in 1.4.0
fun onCaptureStarted(): Unit

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
fun onCaptureSuccess(image: ImageProxy): Unit

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 or JPEG_R, 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
image: ImageProxy

The captured image

onError

Added in 1.0.0
fun onError(exception: ImageCaptureException): Unit

Callback for when an error occurred during image capture.

Parameters
exception: ImageCaptureException

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

onPostviewBitmapAvailable

Added in 1.4.0
fun onPostviewBitmapAvailable(bitmap: Bitmap): Unit

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
bitmap: Bitmap

the postview bitmap.