Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

# PostProcessor

*** ** * ** ***

` public interface PostProcessor `   
` `

|---|
| android.graphics.PostProcessor |

<br />

*** ** * ** ***

Helper interface for adding custom processing to an image.

The image being processed may be a `https://developer.android.com/reference/android/graphics/drawable/Drawable`, a `https://developer.android.com/reference/android/graphics/Bitmap`, or a frame of an `https://developer.android.com/reference/android/graphics/drawable/AnimatedImageDrawable` produced by `https://developer.android.com/reference/android/graphics/ImageDecoder`. This is called before the requested object is returned.

This custom processing can even be applied to images that will be returned as immutable objects, such as a `https://developer.android.com/reference/android/graphics/Bitmap` with `Config` `https://developer.android.com/reference/android/graphics/Bitmap.Config#HARDWARE` returned by `https://developer.android.com/reference/android/graphics/ImageDecoder`.

On an `https://developer.android.com/reference/android/graphics/drawable/AnimatedImageDrawable`, the callback will only be called once, but the drawing commands will be applied to each frame, as if the `https://developer.android.com/reference/android/graphics/Canvas` had been returned by `https://developer.android.com/reference/android/graphics/Picture#beginRecording(int,%20int)`.

<br />

Supplied to ImageDecoder via `https://developer.android.com/reference/android/graphics/ImageDecoder#setPostProcessor(android.graphics.PostProcessor)`.

<br />

## Summary

| ### Public methods ||
|---|---|
| ` abstract int` | ` https://developer.android.com/reference/android/graphics/PostProcessor#onPostProcess(android.graphics.Canvas)(https://developer.android.com/reference/android/graphics/Canvas canvas) ` Do any processing after (for example) decoding. |

## Public methods

### onPostProcess

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public abstract int onPostProcess (Canvas canvas)
```

Do any processing after (for example) decoding.

Drawing to the `https://developer.android.com/reference/android/graphics/Canvas` will behave as if the initial processing (e.g. decoding) already exists in the Canvas. An implementation can draw effects on top of this, or it can even draw behind it using `https://developer.android.com/reference/android/graphics/PorterDuff.Mode#DST_OVER`. A common effect is to add transparency to the corners to achieve rounded corners. That can be done with the following code:

```
 Path path = new Path();
 path.setFillType(Path.FillType.INVERSE_EVEN_ODD);
 int width = canvas.getWidth();
 int height = canvas.getHeight();
 path.addRoundRect(0, 0, width, height, 20, 20, Path.Direction.CW);
 Paint paint = new Paint();
 paint.setAntiAlias(true);
 paint.setColor(Color.TRANSPARENT);
 paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
 canvas.drawPath(path, paint);
 return PixelFormat.TRANSLUCENT;
 
```

<br />

<br />

| Parameters ||
|---|---|
| `canvas` | `Canvas`: The `https://developer.android.com/reference/android/graphics/Canvas` to draw to. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `int` | Opacity of the result after drawing. `https://developer.android.com/reference/android/graphics/PixelFormat#UNKNOWN` means that the implementation did not change whether the image has alpha. Return this unless you added transparency (e.g. with the code above, in which case you should return `https://developer.android.com/reference/android/graphics/PixelFormat#TRANSLUCENT`) or you forced the image to be opaque (e.g. by drawing everywhere with an opaque color and `https://developer.android.com/reference/android/graphics/PorterDuff.Mode#DST_OVER`, in which case you should return `https://developer.android.com/reference/android/graphics/PixelFormat#OPAQUE`). `https://developer.android.com/reference/android/graphics/PixelFormat#TRANSLUCENT` means that the implementation added transparency. This is safe to return even if the image already had transparency. This is also safe to return if the result is opaque, though it may draw more slowly. `https://developer.android.com/reference/android/graphics/PixelFormat#OPAQUE` means that the implementation forced the image to be opaque. This is safe to return even if the image was already opaque. `https://developer.android.com/reference/android/graphics/PixelFormat#TRANSPARENT` (or any other integer) is not allowed, and will result in throwing an `https://developer.android.com/reference/java/lang/IllegalArgumentException`. Value is one of the following: - `https://developer.android.com/reference/android/graphics/PixelFormat#UNKNOWN` - `https://developer.android.com/reference/android/graphics/PixelFormat#TRANSLUCENT` - `https://developer.android.com/reference/android/graphics/PixelFormat#TRANSPARENT` - `https://developer.android.com/reference/android/graphics/PixelFormat#OPAQUE` |