private Bitmap bitmapSrc;
private Bitmap bitmapDst;
private Paint mPaint = new Paint();
public RoundImageview(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
//使用Xfermode时,关闭硬件加速
setLayerType(LAYER_TYPE_SOFTWARE, null);
bitmapSrc = BitmapFactory.decodeResource(getResources(), R.mipmap.xyjy6);
bitmapDst = BitmapFactory.decodeResource(getResources(), R.mipmap.shade);
mPaint.setAntiAlias(true);
mPaint.setDither(true);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawBitmap(bitmapDst,0,0,mPaint);
//后画SRC的图片
Xfermode xfermode = new PorterDuffXfermode(PorterDuff.Mode.SRC_IN);
mPaint.setXfermode(xfermode);
canvas.drawBitmap(bitmapSrc,0,0,mPaint);
mPaint.setXfermode(null);
}