# ImageProcessor

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/ImageProcessor.java+class:androidx.camera.core.ImageProcessor) Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/camera#1.3.0)

*** ** * ** ***

<br />

```
public interface ImageProcessor
```

<br />

*** ** * ** ***

Post-processing effect for images.

This interface is for post-processing images. The input is an image from the camera, with the instructions on how to process it; the output is a processed image. CameraX forwards images to the implementation, and delivers the processed images to back the app.

Currently, it can only be used with the `https://developer.android.com/reference/androidx/camera/core/ImageCapture` by targeting `https://developer.android.com/reference/androidx/camera/core/CameraEffect#IMAGE_CAPTURE()`.

If the implementation fails to process the input, it should throw `https://developer.android.com/reference/androidx/camera/core/ProcessingException`. The error will be caught by CameraX and propagated to the app via error callbacks such as `https://developer.android.com/reference/androidx/camera/core/ImageCapture.OnImageSavedCallback#onError(androidx.camera.core.ImageCaptureException)` or `https://developer.android.com/reference/androidx/camera/core/ImageCapture.OnImageCapturedCallback#onError(androidx.camera.core.ImageCaptureException)`.

Code sample:

```
 class ImageProcessorImpl implements ImageProcessor {
     Response process(Request request) throws ProcessingException {
         try {
             ImageProxy image = request.getInputImages().get(0);
             ByteBuffer byteBuffer = image.getPlanes()[0];
             // Process the content of byteBuffer and create a Response object.
         } catch(Exception e) {
             throws new ProcessingException(e);
         }
     }
 }
```

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/camera/core/CameraEffect` |   |

## Summary

| ### Nested types |
|---|
| `public interface https://developer.android.com/reference/androidx/camera/core/ImageProcessor.Request` A request for processing one or multiple `https://developer.android.com/reference/androidx/camera/core/ImageProxy`. |
| `public interface https://developer.android.com/reference/androidx/camera/core/ImageProcessor.Response` A response for returning a processed `https://developer.android.com/reference/androidx/camera/core/ImageProxy` to CameraX. |

| ### Public methods |
|---|---|
| `abstract @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/ImageProcessor.Response` | `https://developer.android.com/reference/androidx/camera/core/ImageProcessor#process(androidx.camera.core.ImageProcessor.Request)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/ImageProcessor.Request request)` Accepts original image from CameraX and returns processed image. |

## Public methods

### process

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

```
abstract @NonNull ImageProcessor.Response process(@NonNull ImageProcessor.Request request)
```

Accepts original image from CameraX and returns processed image.

CameraX invokes this method for each new incoming image. It's invoked on the `https://developer.android.com/reference/java/util/concurrent/Executor.html` provided in `https://developer.android.com/reference/androidx/camera/core/CameraEffect`'s constructor. It might be called in parallel, should the `https://developer.android.com/reference/java/util/concurrent/Executor.html` allow multi-threading. The implementation must block the current calling thread until the output image is returned.

The implementation must follow the instruction in the `https://developer.android.com/reference/androidx/camera/core/ImageProcessor.Request` to process the input image. For example, it must produce an output image with the format following the JavaDoc of `https://developer.android.com/reference/androidx/camera/core/ImageProcessor.Request#getInputImage()`. Failing to do so might cause the processing to fail. For example, for `https://developer.android.com/reference/androidx/camera/core/ImageCapture`, it will cause the `https://developer.android.com/reference/androidx/camera/core/ImageCapture#takePicture(java.util.concurrent.Executor,androidx.camera.core.ImageCapture.OnImageCapturedCallback)` call to fail.

The implementation must throw a `https://developer.android.com/reference/androidx/camera/core/ProcessingException` if it fails to process the `https://developer.android.com/reference/androidx/camera/core/ImageProcessor.Request`. CameraX will catch the error and deliver it to the app via error callbacks. For `https://developer.android.com/reference/androidx/camera/core/ImageCapture`, the error callbacks are `https://developer.android.com/reference/androidx/camera/core/ImageCapture.OnImageCapturedCallback#onError(androidx.camera.core.ImageCaptureException)` or `https://developer.android.com/reference/androidx/camera/core/ImageCapture.OnImageSavedCallback#onError(androidx.camera.core.ImageCaptureException)`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/ImageProcessor.Request request` | a `https://developer.android.com/reference/androidx/camera/core/ImageProcessor.Request` that contains the original image. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/ImageProcessor.Response` | a `https://developer.android.com/reference/androidx/camera/core/ImageProcessor.Response` that contains the processed image. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/camera/core/ProcessingException` | if the implementation fails to process the `https://developer.android.com/reference/androidx/camera/core/ImageProcessor.Request`. |