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:ua.com.spacetv.mycookbook.fragments.FragTextRecipe.java

/**
 * Rounding corners on bitmap//from w w  w.j  a v a  2s .  c o m
 *
 * @param bitmap image of recipe
 * @param pixels - radius
 * @return processed bitmap
 */
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
    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);

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, pixels, pixels, paint);

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

    return output;
}

From source file:com.almalence.googsharing.Thumbnail.java

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int size, int pixels) {
    final int side = Math.min(bitmap.getWidth(), bitmap.getHeight());

    final Bitmap bitmapCropped = Bitmap.createBitmap(bitmap, (bitmap.getWidth() - side) / 2,
            (bitmap.getHeight() - side) / 2, side, side);

    final Bitmap output = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(output);

    final int color = 0xffffffff;
    final Paint paint = new Paint();
    final Rect rectSrc = new Rect(0, 0, bitmapCropped.getWidth(), bitmapCropped.getHeight());
    final Rect rect = new Rect(6, 6, output.getWidth() - 6, output.getHeight() - 6);
    final RectF rectF = new RectF(rect);
    final RectF rectFBorder = new RectF(0, 0, output.getWidth(), output.getHeight());
    final float roundPx = pixels;

    paint.setAntiAlias(true);/*from ww w  .  jav a  2 s. c o m*/
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmapCropped, rectSrc, rect, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.DST_ATOP));
    canvas.drawRoundRect(rectFBorder, roundPx, roundPx, paint);

    return output;
}

From source file:com.mx.hb.moon.swipeRefresh.SwipeProgressBar.java

private void drawTrigger(Canvas canvas, int cx, int cy) {
    mPaint.setColor(mColor1);//  w w w  .  ja  v a  2s  .c o  m
    mPaint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawCircle(cx, cy, cx * mTriggerPercentage, mPaint);
}

From source file:org.jared.synodroid.ds.utils.Utils.java

/**
 * Create a rounded bitmap//from  w ww. jav  a2s  .  co m
 * 
 * @param bitmap
 *            The original bitmap
 * @return
 */
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) {
    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, roundPx, roundPx, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}

From source file:net.kourlas.voipms_sms.Utils.java

/**
 * Applies a circular mask to a bitmap./*from  w ww. jav  a  2  s  .  c o  m*/
 *
 * @param bitmap The bitmap to apply the mask to.
 */
public static Bitmap applyCircularMask(Bitmap bitmap) {
    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());

    canvas.drawARGB(0, 0, 0, 0);
    canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint);
    paint.setAntiAlias(true);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    return output;
}

From source file:com.example.SmartBoard.DrawingView.java

public void changeEraseSize(float size) {
    mode = "erase";
    strokeWidth = (int) size;
    objectModeOff();/*  ww  w  .j  ava 2 s . c  o  m*/
    drawPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    drawPaint.setStrokeWidth(size);
    // mqtt.publishBrushSize(size, "Eraser");
}

From source file:com.example.SmartBoard.DrawingView.java

public void updateEraseSize(float size) {
    mode = "erase";
    objectModeOff();//from  ww  w .  ja v  a2s.co  m
    drawPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    drawPaint.setStrokeWidth(size);
}

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

/**
 * ?Bitmap/*from   w  w w.  java  2  s .c  o m*/
 * 
 * @param bgd
 *            Bitmap
 * @param fg
 *            ?Bitmap
 * @return ???Bitmap
 */
public static Bitmap combineImages(Bitmap bgd, Bitmap fg) {
    Bitmap bmp;

    int width = bgd.getWidth() > fg.getWidth() ? bgd.getWidth() : fg.getWidth();
    int height = bgd.getHeight() > fg.getHeight() ? bgd.getHeight() : fg.getHeight();

    bmp = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    Paint paint = new Paint();
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_ATOP));

    Canvas canvas = new Canvas(bmp);
    canvas.drawBitmap(bgd, 0, 0, null);
    canvas.drawBitmap(fg, 0, 0, paint);

    return bmp;
}

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

/**
 * ?//  w w w  .j  a  v  a 2s  . com
 * 
 * @param bgd
 *            ?Bitmap
 * @param fg
 *            ?Bitmap
 * @return ???Bitmap
 */
public static Bitmap combineImagesToSameSize(Bitmap bgd, Bitmap fg) {
    Bitmap bmp;

    int width = bgd.getWidth() < fg.getWidth() ? bgd.getWidth() : fg.getWidth();
    int height = bgd.getHeight() < fg.getHeight() ? bgd.getHeight() : fg.getHeight();

    if (fg.getWidth() != width && fg.getHeight() != height) {
        fg = zoom(fg, width, height);
    }
    if (bgd.getWidth() != width && bgd.getHeight() != height) {
        bgd = zoom(bgd, width, height);
    }

    bmp = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    Paint paint = new Paint();
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_ATOP));

    Canvas canvas = new Canvas(bmp);
    canvas.drawBitmap(bgd, 0, 0, null);
    canvas.drawBitmap(fg, 0, 0, paint);

    return bmp;
}

From source file:com.android.mms.ui.MessageUtils.java

public static Bitmap getCircularBitmap(Bitmap bitmap) {
    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 = bitmap.getWidth() / 2;

    paint.setAntiAlias(true);//from  w ww.j  a  va  2  s .  c om
    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;
}