Example usage for android.graphics PorterDuffXfermode PorterDuffXfermode

List of usage examples for android.graphics PorterDuffXfermode PorterDuffXfermode

Introduction

In this page you can find the example usage for android.graphics PorterDuffXfermode PorterDuffXfermode.

Prototype

public PorterDuffXfermode(PorterDuff.Mode mode) 

Source Link

Document

Create an xfermode that uses the specified porter-duff mode.

Usage

From source file:com.scvngr.levelup.core.ui.view.LevelUpCodeView.java

/**
 * Initialize the view.//from  ww w . ja v  a2s. c om
 *
 * @param context view context.
 */
private void init(@NonNull final Context context) {
    setWillNotDraw(false);
    setClickable(true);

    final Resources res = context.getResources();
    final Xfermode xferMode = new PorterDuffXfermode(Mode.SCREEN);

    if (!isInEditMode()) {
        mTargetBottomLeftPaint.setColor(res.getColor(R.color.levelup_logo_green));
        mTargetBottomRightPaint.setColor(res.getColor(R.color.levelup_logo_blue));
        mTargetTopRightPaint.setColor(res.getColor(R.color.levelup_logo_orange));
    } else {
        mTargetBottomLeftPaint.setColor(Color.GREEN);
        mTargetBottomRightPaint.setColor(Color.BLUE);
        mTargetTopRightPaint.setColor(Color.YELLOW);
    }

    mTargetBottomLeftPaint.setXfermode(xferMode);
    mTargetBottomRightPaint.setXfermode(xferMode);
    mTargetTopRightPaint.setXfermode(xferMode);

    mGestureDetector = new GestureDetectorCompat(context, mGestureDetectorCallbacks);
}

From source file:com.dwdesign.tweetings.fragment.UserProfileFragment.java

public static Bitmap createAlphaGradientBitmap(Bitmap orig) {
    final int width = orig.getWidth(), height = orig.getHeight();
    final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(bitmap);
    final Paint paint = new Paint();
    final LinearGradient shader = new LinearGradient(width / 2, 0, width / 2, height, 0xffffffff, 0x00ffffff,
            Shader.TileMode.CLAMP);/*from w  ww  .  java  2 s.co m*/
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    canvas.drawBitmap(orig, 0, 0, null);
    canvas.drawRect(0, 0, width, height, paint);
    return bitmap;
}

From source file:org.mariotaku.twidere.view.ShapedImageView.java

private void updateShadowBitmap() {
    if (useOutline())
        return;/*from   w ww  .  j a va 2 s . c om*/
    final int width = getWidth(), height = getHeight();
    if (width <= 0 || height <= 0)
        return;
    final int contentLeft = getPaddingLeft(), contentTop = getPaddingTop(),
            contentRight = width - getPaddingRight(), contentBottom = height - getPaddingBottom();
    final int contentWidth = contentRight - contentLeft, contentHeight = contentBottom - contentTop;
    final float radius = mShadowRadius, dy = radius * 1.5f / 2;
    final int size = Math.round(Math.min(contentWidth, contentHeight) + radius * 2);
    mShadowBitmap = Bitmap.createBitmap(size, Math.round(size + dy), Config.ARGB_8888);
    Canvas canvas = new Canvas(mShadowBitmap);
    final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(0xFF000000 | mBackgroundPaint.getColor());
    paint.setShadowLayer(radius, 0, radius * 1.5f / 2, SHADOW_START_COLOR);
    final RectF rect = new RectF(radius, radius, size - radius, size - radius);
    if (getStyle() == SHAPE_CIRCLE) {
        canvas.drawOval(rect, paint);
        paint.setShadowLayer(0, 0, 0, 0);
        paint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));
        canvas.drawOval(rect, paint);
    } else {
        final float cr = getCalculatedCornerRadius();
        canvas.drawRoundRect(rect, cr, cr, paint);
        paint.setShadowLayer(0, 0, 0, 0);
        paint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));
        canvas.drawRoundRect(rect, cr, cr, paint);
    }
    invalidate();
}

From source file:org.getlantern.firetweet.view.ShapedImageView.java

private void updateShadowBitmap() {
    if (USE_OUTLINE)
        return;/*from  w  w  w  .  j a  v a2s  . c om*/
    final int width = getWidth(), height = getHeight();
    if (width <= 0 || height <= 0)
        return;
    final int contentLeft = getPaddingLeft(), contentTop = getPaddingTop(),
            contentRight = width - getPaddingRight(), contentBottom = height - getPaddingBottom();
    final int contentWidth = contentRight - contentLeft, contentHeight = contentBottom - contentTop;
    final float radius = mShadowRadius, dy = radius * 1.5f / 2;
    final int size = Math.round(Math.min(contentWidth, contentHeight) + radius * 2);
    mShadowBitmap = Bitmap.createBitmap(size, Math.round(size + dy), Config.ARGB_8888);
    Canvas canvas = new Canvas(mShadowBitmap);
    final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(0xFF000000 | mBackgroundPaint.getColor());
    paint.setShadowLayer(radius, 0, radius * 1.5f / 2, SHADOW_START_COLOR);
    final RectF rect = new RectF(radius, radius, size - radius, size - radius);
    if (getStyle() == SHAPE_CIRCLE) {
        canvas.drawOval(rect, paint);
        paint.setShadowLayer(0, 0, 0, 0);
        paint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));
        canvas.drawOval(rect, paint);
    } else {
        final float cr = getCalculatedCornerRadius();
        canvas.drawRoundRect(rect, cr, cr, paint);
        paint.setShadowLayer(0, 0, 0, 0);
        paint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));
        canvas.drawRoundRect(rect, cr, cr, paint);
    }
    invalidate();
}

From source file:com.linhnv.apps.maxim.utils.ImageWorker.java

private BitmapDrawable roundCornered(BitmapDrawable scaledBitmap, int i) {

    Bitmap bitmap = scaledBitmap.getBitmap();

    Bitmap result = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(result);

    int color = 0xff424242;
    Paint paint = new Paint();
    Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    RectF rectF = new RectF(rect);
    int roundPx = i;
    paint.setAntiAlias(true);/*from  w  ww.ja v a2  s  . c o  m*/
    canvas.drawARGB(0, 0, 0, 0);
    // paint.setColor(Color.BLUE);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    BitmapDrawable finalresult = new BitmapDrawable(mResources, result);
    return finalresult;
}

From source file:com.yk.notification.util.BitmapUtil.java

/**
 * ??//  ww w.  j  a  v  a2 s . co m
 * 
 * @param bitmap
 *            Bitmap
 * @return Bitmap
 */
public static Bitmap getRoundBitmap(Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    float roundPx;
    float left, top, right, bottom, dst_left, dst_top, dst_right, dst_bottom;
    if (width <= height) {
        roundPx = width / 2;
        top = 0;
        bottom = width;
        left = 0;
        right = width;
        height = width;
        dst_left = 0;
        dst_top = 0;
        dst_right = width;
        dst_bottom = width;
    } else {
        roundPx = height / 2;
        float clip = (width - height) / 2;
        left = clip;
        right = width - clip;
        top = 0;
        bottom = height;
        width = height;
        dst_left = 0;
        dst_top = 0;
        dst_right = height;
        dst_bottom = height;
    }

    Bitmap output = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect src = new Rect((int) left, (int) top, (int) right, (int) bottom);
    final Rect dst = new Rect((int) dst_left, (int) dst_top, (int) dst_right, (int) dst_bottom);
    final RectF rectF = new RectF(dst);

    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, src, dst, paint);
    return output;
}

From source file:com.bamobile.fdtks.util.Tools.java

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
    Bitmap output;//from  w  w  w.  j  ava2  s .c om

    if (bitmap.getWidth() > bitmap.getHeight()) {
        output = Bitmap.createBitmap(bitmap.getHeight(), bitmap.getHeight(), Config.ARGB_8888);
    } else {
        output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getWidth(), 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());

    float r = 0;

    if (bitmap.getWidth() > bitmap.getHeight()) {
        r = bitmap.getHeight() / 2;
    } else {
        r = bitmap.getWidth() / 2;
    }

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawCircle(r, r, r, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;

}

From source file:mil.nga.giat.mage.sdk.utils.MediaUtility.java

public static Bitmap resizeAndRoundCorners(Bitmap bitmap, int maxSize) {
    boolean isLandscape = bitmap.getWidth() > bitmap.getHeight();

    int newWidth, newHeight;
    if (isLandscape) {
        newWidth = maxSize;//from   w ww  .ja  va 2s.co m
        newHeight = Math.round(((float) newWidth / bitmap.getWidth()) * bitmap.getHeight());
    } else {
        newHeight = maxSize;
        newWidth = Math.round(((float) newHeight / bitmap.getHeight()) * bitmap.getWidth());
    }

    Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, false);

    if (resizedBitmap != bitmap)
        bitmap.recycle();

    Bitmap roundedProfile = Bitmap.createBitmap(resizedBitmap.getWidth(), resizedBitmap.getHeight(),
            Config.ARGB_8888);

    Canvas roundedCanvas = new Canvas(roundedProfile);
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, roundedProfile.getWidth(), roundedProfile.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = 7.0f;

    paint.setAntiAlias(true);
    roundedCanvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    roundedCanvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    roundedCanvas.drawBitmap(resizedBitmap, rect, rect, paint);
    return roundedProfile;
}

From source file:me.tb.player.SkeletonActivity.java

@Override
public Bitmap getCircleBitmap(Bitmap bitmap) {
    final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(output);

    final int color = Color.RED;
    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);/*from w w  w .j  a  va2  s  .c  o m*/
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawOval(rectF, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    bitmap.recycle();

    return output;
}

From source file:com.wanikani.androidnotifier.DashboardFragment.java

/**
 * Apply a circular mask on the given bitmap. This method is
 * used to display the avatar./* ww  w. j a  v a  2  s  . c om*/
 * @param bmp an input bitmap
 * @param result the output (masked) bitmap
 */
private Bitmap mask(Bitmap bmp) {
    Bitmap result, mask;
    Drawable dmask;
    Canvas canvas;
    Paint paint;

    result = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), Bitmap.Config.ARGB_8888);
    canvas = new Canvas(result);

    dmask = getResources().getDrawable(R.drawable.gravatar_mask);
    mask = ((BitmapDrawable) dmask).getBitmap();

    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    canvas.drawBitmap(bmp, 0, 0, null);
    canvas.drawBitmap(mask, 0, 0, paint);

    return result;
}