I don't know how to call the outer-space of a circle... a mask or inverse-space? I hope you will understand what I'm trying to say by seeing the images.
Original image:
Custom view:
As you can see, I want to apply that transparent-black color to my view, but I don't know where to start.
public class MaskView extends View {
private int mBackgroundColor;
public MaskView(Context context) {
super(context);
init();
}
public MaskView(Context context, AttributeSet set) {
super(context, set);
init();
}
public MaskView(Context context, AttributeSet set, int defStyle) {
super(context, set, defStyle);
init();
}
private void init() {
mBackgroundColor = Color.parseColor("#AA000000");
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawColor(mBackgroundColor);
}
}
it achievable with the PorterDuff . You can allocate a painter object, specifying the PorterDuff mode you need, and drawing the a circle with that paint, and accordingly to the mode you have to draw before or after the bitmap
canvas.drawCircle(getWidth()/2, getWidth()/2, getWidth()/2, mPorterDuffPainter);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.