Search in sources :

Example 1 with Xfermode

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);
}
Also used : PorterDuffXfermode(android.graphics.PorterDuffXfermode) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Xfermode(android.graphics.Xfermode)

Example 2 with 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);
    }
}
Also used : RectF(android.graphics.RectF) Rect(android.graphics.Rect) PorterDuffXfermode(android.graphics.PorterDuffXfermode) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Xfermode(android.graphics.Xfermode) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Aggregations

PorterDuffXfermode (android.graphics.PorterDuffXfermode)2 Xfermode (android.graphics.Xfermode)2 Paint (android.graphics.Paint)1 Rect (android.graphics.Rect)1 RectF (android.graphics.RectF)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 Drawable (android.graphics.drawable.Drawable)1