use of android.graphics.Xfermode in project android-jigsaw-puzzle by julesbond007.
the class DrawingView method setErase.
/**
* Set erase to true when the erase button is clicked.
*
* @param isErase {@code true} if erase is clicked {@code false} otherwise
*/
public void setErase(boolean isErase) {
Xfermode xfermode = isErase ? new PorterDuffXfermode(PorterDuff.Mode.CLEAR) : null;
drawPaint.setXfermode(xfermode);
}
use of android.graphics.Xfermode in project BlurKit-Android by flurgle.
the class RoundedImageView method onDraw.
@Override
protected void onDraw(Canvas canvas) {
Drawable myDrawable = getDrawable();
if (myDrawable != null && myDrawable instanceof BitmapDrawable && mCornerRadius > 0) {
Paint paint = ((BitmapDrawable) myDrawable).getPaint();
final int color = 0xff000000;
Rect bitmapBounds = myDrawable.getBounds();
final RectF rectF = new RectF(bitmapBounds);
int saveCount = canvas.saveLayer(rectF, null, Canvas.MATRIX_SAVE_FLAG | Canvas.CLIP_SAVE_FLAG | Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG);
getImageMatrix().mapRect(rectF);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, mCornerRadius, mCornerRadius, paint);
Xfermode oldMode = paint.getXfermode();
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
super.onDraw(canvas);
paint.setXfermode(oldMode);
canvas.restoreToCount(saveCount);
} else {
super.onDraw(canvas);
}
}
Aggregations