IPostProcessor.OnPostProcess(Canvas) Method

Definition

Do any processing after (for example) decoding.

[Android.Runtime.Register("onPostProcess", "(Landroid/graphics/Canvas;)I", "GetOnPostProcess_Landroid_graphics_Canvas_Handler:Android.Graphics.IPostProcessorInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince=28)]
public int OnPostProcess (Android.Graphics.Canvas canvas);
[<Android.Runtime.Register("onPostProcess", "(Landroid/graphics/Canvas;)I", "GetOnPostProcess_Landroid_graphics_Canvas_Handler:Android.Graphics.IPostProcessorInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince=28)>]
abstract member OnPostProcess : Android.Graphics.Canvas -> int

Parameters

canvas
Canvas

The Canvas to draw to.

Returns

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

Attributes

Remarks

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 PorterDuff.Mode#DST_OVER 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;

Java documentation for android.graphics.PostProcessor.onPostProcess(android.graphics.Canvas).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to