Search in sources :

Example 51 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project UltimateAndroid by cymcsg.

the class RippleView method getCircleBitmap.

private Bitmap getCircleBitmap(final int radius) {
    final Bitmap output = Bitmap.createBitmap(originBitmap.getWidth(), originBitmap.getHeight(), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(output);
    final Paint paint = new Paint();
    final Rect rect = new Rect((int) (x - radius), (int) (y - radius), (int) (x + radius), (int) (y + radius));
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    canvas.drawCircle(x, y, radius, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(originBitmap, rect, rect, paint);
    return output;
}
Also used : Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint)

Example 52 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project Android-Image-Cropper by ArthurHub.

the class CropImage method toOvalBitmap.

/**
     * Create a new bitmap that has all pixels beyond the oval shape transparent.
     * Old bitmap is recycled.
     */
public static Bitmap toOvalBitmap(@NonNull Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    int color = 0xff424242;
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    RectF rect = new RectF(0, 0, width, height);
    canvas.drawOval(rect, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, 0, 0, paint);
    bitmap.recycle();
    return output;
}
Also used : RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 53 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project android-bootstrap by AndroidBootstrap.

the class ImageUtils method roundCorners.

/**
     * Round the corners of a {@link Bitmap}
     *
     * @param source
     * @param radius
     * @return rounded corner bitmap
     */
public static Bitmap roundCorners(final Bitmap source, final float radius) {
    final int width = source.getWidth();
    final int height = source.getHeight();
    final Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(WHITE);
    final Bitmap clipped = Bitmap.createBitmap(width, height, ARGB_8888);
    Canvas canvas = new Canvas(clipped);
    canvas.drawRoundRect(new RectF(0, 0, width, height), radius, radius, paint);
    paint.setXfermode(new PorterDuffXfermode(DST_IN));
    final Bitmap rounded = Bitmap.createBitmap(width, height, ARGB_8888);
    canvas = new Canvas(rounded);
    canvas.drawBitmap(source, 0, 0, null);
    canvas.drawBitmap(clipped, 0, 0, paint);
    source.recycle();
    clipped.recycle();
    return rounded;
}
Also used : RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) Point(android.graphics.Point) Paint(android.graphics.Paint)

Example 54 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project Notes by Elder-Wu.

the class GuaGuaKa method onDraw.

@Override
protected void onDraw(Canvas canvas) {
    canvas.drawBitmap(backBitmap, 0, 0, null);
    pathPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
    cacheCanvas.drawPath(path, pathPaint);
    canvas.drawBitmap(cacheBitmap, 0, 0, null);
}
Also used : PorterDuffXfermode(android.graphics.PorterDuffXfermode)

Example 55 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project android_frameworks_base by DirtyUnicorns.

the class UserIconDrawable method setBadge.

public UserIconDrawable setBadge(Drawable badge) {
    mBadge = badge;
    if (mBadge != null) {
        if (mClearPaint == null) {
            mClearPaint = new Paint();
            mClearPaint.setAntiAlias(true);
            mClearPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
            mClearPaint.setStyle(Paint.Style.FILL);
        }
        // update metrics
        onBoundsChange(getBounds());
    } else {
        invalidateSelf();
    }
    return this;
}
Also used : PorterDuffXfermode(android.graphics.PorterDuffXfermode) Paint(android.graphics.Paint)

Aggregations

PorterDuffXfermode (android.graphics.PorterDuffXfermode)152 Paint (android.graphics.Paint)127 Canvas (android.graphics.Canvas)103 Bitmap (android.graphics.Bitmap)92 Rect (android.graphics.Rect)65 RectF (android.graphics.RectF)51 Matrix (android.graphics.Matrix)11 LinearGradient (android.graphics.LinearGradient)10 SuppressLint (android.annotation.SuppressLint)9 TypedArray (android.content.res.TypedArray)8 Point (android.graphics.Point)6 IOException (java.io.IOException)6 BitmapDrawable (android.graphics.drawable.BitmapDrawable)5 ColorMatrix (android.graphics.ColorMatrix)4 Path (android.graphics.Path)4 Resources (android.content.res.Resources)3 Drawable (android.graphics.drawable.Drawable)3 ResourceHelper (com.klinker.android.launcher.api.ResourceHelper)3 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)3 RadialGradient (android.graphics.RadialGradient)2