Search in sources :

Example 61 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project muzei by romannurik.

the class SettingsChooseSourceFragment method prepareGenerateSourceImages.

private void prepareGenerateSourceImages() {
    mImageFillPaint.setColor(Color.WHITE);
    mImageFillPaint.setAntiAlias(true);
    mAlphaPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
    mSelectedSourceImage = new BitmapDrawable(getResources(), generateSourceImage(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_source_selected, null)));
}
Also used : PorterDuffXfermode(android.graphics.PorterDuffXfermode) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 62 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project smartmodule by carozhu.

the class Bitmaputil method getCroppedBitmap.

/**
     * @param bitmap
     * @return 返回一个圆型图片 应用场景:当你的ImageView/view 想要为它设置一张圆形图片时
     */
public static Bitmap getCroppedBitmap(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    // 设置一个图片大小的矩形
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    // bm是一个刚好canvas大小的空Bitmap ,画完后应该会自动保存到bm
    Canvas canvas = new Canvas(output);
    final Paint paint = new Paint();
    paint.setAntiAlias(true);
    int halfWidth = bitmap.getWidth() / 2;
    int halfHeight = bitmap.getHeight() / 2;
    // 画圆
    canvas.drawCircle(halfWidth, halfHeight, Math.max(halfWidth, halfHeight), paint);
    // 设置为取两层图像交集部门,只显示上层图像
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    // Mode -设置Mode模式可以画出一些常见的模型
    // paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    // 画图像
    canvas.drawBitmap(bitmap, 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) Paint(android.graphics.Paint)

Example 63 with PorterDuffXfermode

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

the class ImageHelper method getRoundedCornerBitmap.

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
    if (bitmap == null) {
        return null;
    }
    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);
    final float roundPx = 24;
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, 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 64 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project smartmodule by carozhu.

the class RoundRectangleImageView method getRoundBitmap.

/**
	 * 获取圆角矩形图片方法
	 * 
	 * @param bitmap
	 * @param roundPx
	 *            ,一般设置成14
	 * @return Bitmap
	 */
private Bitmap getRoundBitmap(Bitmap bitmap, int roundPx) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final int color = 0xff424242;
    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);
    int x = bitmap.getWidth();
    canvas.drawRoundRect(rectF, roundPx, roundPx, 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)

Example 65 with PorterDuffXfermode

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

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