public abstract class

ImageCapture.OnImageCapturedCallback

extends java.lang.Object

 java.lang.Object

↳androidx.camera.core.ImageCapture.OnImageCapturedCallback

Overview

Callback for image capture events.

Summary

Constructors
publicOnImageCapturedCallback()

Methods
public voidonCaptureProcessProgressed(int progress)

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

public voidonCaptureStarted()

Callback for when the camera has started exposing a frame.

public voidonCaptureSuccess(ImageProxy image)

Callback for when the image has been captured.

public voidonError(ImageCaptureException exception)

Callback for when an error occurred during image capture.

public voidonPostviewBitmapAvailable(Bitmap bitmap)

Callback to notify that the postview bitmap is available.

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

Constructors

public OnImageCapturedCallback()

Methods

public void onCaptureStarted()

Callback for when the camera has started exposing a frame.

This callback is guaranteed to be called once and before ImageCapture.OnImageCapturedCallback.onCaptureSuccess(ImageProxy) for the same invocation of ImageCapture.takePicture(Executor, ImageCapture.OnImageCapturedCallback).

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

public void onCaptureSuccess(ImageProxy image)

Callback for when the image has been captured.

The application is responsible for calling ImageProxy.close() to close the image.

The image is of format or , queryable via ImageProxy.getFormat().

The image is provided as captured by the underlying 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 ImageCapture.Builder.setTargetRotation(int) and ImageCapture.setTargetRotation(int).

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: The captured image

public void onError(ImageCaptureException exception)

Callback for when an error occurred during image capture.

Parameters:

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

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 ImageCapture.getImageCaptureCapabilities(CameraInfo) and ImageCaptureCapabilities.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 ImageCapture.OnImageCapturedCallback.onCaptureSuccess(ImageProxy).

Parameters:

progress: the progress ranging from 0 to 100.

public void onPostviewBitmapAvailable(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 ImageCaptureCapabilities.isPostviewSupported() returns true for the specified CameraInfo and applications must explicitly enable the postview using the ImageCapture.OutputFileOptions.Builder. This callback will be called before ImageCapture.OnImageCapturedCallback.onCaptureSuccess(ImageProxy). 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 ImageCapture.Builder.setTargetRotation(int) and ImageCapture.setTargetRotation(int).

Parameters:

bitmap: the postview bitmap.