Skip to content

Most visited

Recently visited



public interface PostProcessor

Helper interface for adding custom processing to an image.

The image being processed may be a Drawable, Bitmap or frame of an animated image produced by ImageDecoder. This is called before the requested object is returned.

This custom processing also applies to image types that are otherwise immutable, such as HARDWARE.

On an animated image, the callback will only be called once, but the drawing commands will be applied to each frame, as if the Canvas had been returned by beginRecording(int, int).

Supplied to ImageDecoder via setPostProcessor(PostProcessor).


Public methods

abstract int onPostProcess(Canvas canvas)

Do any processing after (for example) decoding.

Public methods


int onPostProcess (Canvas canvas)

Do any processing after (for example) decoding.

Drawing to the 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 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;

canvas Canvas: The Canvas to draw to.

This value must never be null.

int Opacity of the result after drawing. 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 PixelFormat.TRANSLUCENT) or you forced the image to be opaque (e.g. by drawing everywhere with an opaque color and PorterDuff.Mode.DST_OVER, in which case you should return PixelFormat.OPAQUE). 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. OPAQUE means that the implementation forced the image to be opaque. This is safe to return even if the image was already opaque. TRANSPARENT (or any other integer) is not allowed, and will result in throwing an IllegalArgumentException.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields


Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)