Search in sources :

Example 11 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project LikeAnimation by frogermcs.

the class CircleView method init.

private void init() {
    circlePaint.setStyle(Paint.Style.FILL);
    maskPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
}
Also used : PorterDuffXfermode(android.graphics.PorterDuffXfermode)

Example 12 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project WordPress-Android by wordpress-mobile.

the class ImageUtils method getRoundedEdgeBitmap.

/**
     * Returns the passed bitmap with rounded corners
     * @param bitmap - the bitmap to modify
     * @param radius - the radius of the corners
     * @param borderColor - the border to apply (use Color.TRANSPARENT for none)
     */
public static Bitmap getRoundedEdgeBitmap(final Bitmap bitmap, int radius, int borderColor) {
    if (bitmap == null) {
        return null;
    }
    final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(output);
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.RED);
    canvas.drawRoundRect(rectF, radius, radius, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    if (borderColor != Color.TRANSPARENT) {
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(1f);
        paint.setColor(borderColor);
        canvas.drawRoundRect(rectF, radius, radius, paint);
    }
    return output;
}
Also used : RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint)

Example 13 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project ZI by yixia.

the class BitmapHelper method getRoundedCornerBitmap.

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float radius) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, radius, radius, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}
Also used : RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 14 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project PhotoNoter by yydcdut.

the class RoundedImageView method getCroppedBitmap.

public static Bitmap getCroppedBitmap(Bitmap bmp, int radius) {
    Bitmap sbmp;
    if (bmp.getWidth() != radius || bmp.getHeight() != radius) {
        sbmp = Bitmap.createScaledBitmap(bmp, radius, radius, false);
    } else {
        sbmp = bmp;
    }
    Bitmap output = Bitmap.createBitmap(sbmp.getWidth(), sbmp.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, sbmp.getWidth(), sbmp.getHeight());
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.parseColor("#BAB399"));
    canvas.drawCircle(sbmp.getWidth() / 2 + 0.7f, sbmp.getHeight() / 2 + 0.7f, sbmp.getWidth() / 2 + 0.1f, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(sbmp, 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 15 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project weiciyuan by qii.

the class ImageEditUtility method getRoundedCornerBitmap.

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int cornerRadius) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = cornerRadius;
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    bitmap.recycle();
    return output;
}
Also used : RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) 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