ax1mx2 ax1mx2 - 1 month ago 13
Android Question

Drawing with Transparent Paint on Android

When I use

Paint
with
Color.TRANSPARENT
on a normal 2D canvas in Android, I don't get any results and my intention was to get rid of some of the contents on the canvas. I mean the contents that I want to dispose of don't disappear.

This is the code for my
Paint
:

mPointFillPaint = new Paint();
mPointFillPaint.setColor(Color.TRANSPARENT);
mPointFillPaint.setAntiAlias(true);
mPointFillPaint.setStyle(Paint.Style.FILL);
mPointFillPaint.setStrokeJoin(Paint.Join.MITER);

Answer

The following Paint configuration should help:

mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setColor(Color.TRANSPARENT);
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT));
mPaint.setAntiAlias(true);