# ImageCapture.OnImageCapturedCallback

Artifact: [androidx.camera:camera-core](https://developer.android.com/jetpack/androidx/releases/camera) [View Source](https://cs.android.com/search?q=file:androidx/camera/core/ImageCapture.java+class:androidx.camera.core.ImageCapture.OnImageCapturedCallback) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/camera#1.0.0)

*** ** * ** ***


```
public abstract class ImageCapture.OnImageCapturedCallback
```

<br />

*** ** * ** ***

Callback for image capture events.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/camera/core/ImageCapture.OnImageCapturedCallback#OnImageCapturedCallback()()` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/camera/core/ImageCapture.OnImageCapturedCallback#onCaptureProcessProgressed(int)(int progress)` Callback to report the progress of the capture's processing. |
| `void` | `https://developer.android.com/reference/androidx/camera/core/ImageCapture.OnImageCapturedCallback#onCaptureStarted()()` Callback for when the camera has started exposing a frame. |
| `void` | `https://developer.android.com/reference/androidx/camera/core/ImageCapture.OnImageCapturedCallback#onCaptureSuccess(androidx.camera.core.ImageProxy)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/ImageProxy image)` Callback for when the image has been captured. |
| `void` | `https://developer.android.com/reference/androidx/camera/core/ImageCapture.OnImageCapturedCallback#onError(androidx.camera.core.ImageCaptureException)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/ImageCaptureException exception)` Callback for when an error occurred during image capture. |
| `void` | `https://developer.android.com/reference/androidx/camera/core/ImageCapture.OnImageCapturedCallback#onPostviewBitmapAvailable(android.graphics.Bitmap)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Bitmap.html bitmap)` 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](https://developer.android.com/jetpack/androidx/releases/camera#1.4.0)

```
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 `https://developer.android.com/reference/androidx/camera/core/ImageCapture#getImageCaptureCapabilities(androidx.camera.core.CameraInfo)` and `https://developer.android.com/reference/androidx/camera/core/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 `https://developer.android.com/reference/androidx/camera/core/ImageCapture.OnImageCapturedCallback#onCaptureSuccess(androidx.camera.core.ImageProxy)`.

| Parameters |
|---|---|
| `int progress` | the progress ranging from 0 to 100. |

### onCaptureStarted

Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/camera#1.4.0)

```
public void onCaptureStarted()
```

Callback for when the camera has started exposing a frame.

This callback is guaranteed to be called once and before `https://developer.android.com/reference/androidx/camera/core/ImageCapture.OnImageCapturedCallback#onCaptureSuccess(androidx.camera.core.ImageProxy)` for the same invocation of `https://developer.android.com/reference/androidx/camera/core/ImageCapture#takePicture(java.util.concurrent.Executor,androidx.camera.core.ImageCapture.OnImageCapturedCallback)`.

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

### onCaptureSuccess

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/camera#1.0.0)

```
public void onCaptureSuccess(@NonNull ImageProxy image)
```

Callback for when the image has been captured.

The application is responsible for calling `https://developer.android.com/reference/androidx/camera/core/ImageProxy#close()` to close the image.

The image is of format `https://developer.android.com/reference/android/graphics/ImageFormat.html#JPEG` or `https://developer.android.com/reference/android/graphics/ImageFormat.html#JPEG_R`, queryable via `https://developer.android.com/reference/androidx/camera/core/ImageProxy#getFormat()`.

The image is provided as captured by the underlying `https://developer.android.com/reference/android/media/ImageReader.html` 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 `https://developer.android.com/reference/androidx/camera/core/ImageCapture.Builder#setTargetRotation(int)` and `https://developer.android.com/reference/androidx/camera/core/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 `https://developer.android.com/reference/androidx/camera/camera2/package-summary` implementation additional detail can be found in `https://developer.android.com/reference/android/hardware/camera2/CameraDevice.html` documentation.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/ImageProxy image` | The captured image |

### onError

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/camera#1.0.0)

```
public void onError(@NonNull ImageCaptureException exception)
```

Callback for when an error occurred during image capture.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/ImageCaptureException exception` | An `https://developer.android.com/reference/androidx/camera/core/ImageCaptureException` that contains the type of error, the error message and the throwable that caused it. |

### onPostviewBitmapAvailable

Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/camera#1.4.0)

```
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 `https://developer.android.com/reference/androidx/camera/core/ImageCaptureCapabilities#isPostviewSupported()` returns true for the specified `https://developer.android.com/reference/androidx/camera/core/CameraInfo` and applications must explicitly enable the postview using the `https://developer.android.com/reference/androidx/camera/core/ImageCapture.Builder#setPostviewEnabled(boolean)`. This callback will be called before `https://developer.android.com/reference/androidx/camera/core/ImageCapture.OnImageCapturedCallback#onCaptureSuccess(androidx.camera.core.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 `https://developer.android.com/reference/androidx/camera/core/ImageCapture` to make it upright. If target rotation is not set, the display rotation is used.

See also `https://developer.android.com/reference/androidx/camera/core/ImageCapture.Builder#setTargetRotation(int)` and `https://developer.android.com/reference/androidx/camera/core/ImageCapture#setTargetRotation(int)`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Bitmap.html bitmap` | the postview bitmap. |