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.example.SmartBoard.DrawingView.java

private void setDrawPaintRecv(int color, String mode, int brushSize) {
    drawPaintSender.setColor(color);/*from  ww w .  ja v a  2  s.  c o m*/
    drawPaintSender.setStrokeWidth(brushSize);
    if (mode.compareTo("erase") == 0) {
        drawPaintSender.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    } else {
        drawPaintSender.setXfermode(null);
    }
}

From source file:com.cooltechworks.views.ScratchTextView.java

/**
 * Reveals the hidden text by erasing the scratch area.
 *//* w ww . j  av a2  s .  co  m*/
public void reveal() {

    int[] bounds = getTextBounds(1.5f);
    int left = bounds[0];
    int top = bounds[1];
    int right = bounds[2];
    int bottom = bounds[3];

    //        int width = right - left;
    //        int height = bottom - top;
    //        int centerX = left + width / 2;
    //        int centerY = top + height / 2;
    //
    ////        // just to clear more space multiplying by 1.5
    ////        int newWidth = (int) (width * 1.6f);
    ////        int newHeight = (int) (height * 1.6f);
    ////
    ////
    //
    //        left = centerX - width / 2;
    //        top = centerY - height / 2;
    //        right = left + width;
    //        bottom = top + height;

    Paint paint = new Paint();
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));

    mCanvas.drawRect(left, top, right, bottom, paint);
    checkRevealed();
    invalidate();
}

From source file:com.clov4r.moboplayer.android.nil.codec.activity.MoboThumbnailTestActivity.java

public Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) {
    try {//from  w  ww  .ja  v a2 s .  c  o  m
        Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
        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(new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()));
        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(Color.BLACK);
        canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
        paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
        final Rect src = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());

        canvas.drawBitmap(bitmap, src, rect, paint);
        return output;
    } catch (Exception e) {
        return bitmap;
    }
}

From source file:com.linute.linute.API.MyGcmListenerService.java

private static Bitmap getCircleBitmap(Bitmap bitmap) {
    //returns square image for older phones that prefer square notifs
    /*if(Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT){
    return bitmap;//w  w  w. jav  a2  s.  co m
    }*/
    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);
    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.example.android.apis.graphics.FingerPaint.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    mPaint.setXfermode(null);/*from   w w w. ja  va 2  s .  c  om*/
    mPaint.setAlpha(0xFF);

    switch (item.getItemId()) {
    case ERASE_ALL_ID:
        myView.getBitmap().eraseColor(Color.TRANSPARENT);
        myView.invalidate();
        return true;

    case COLOR_MENU_ID:
        new ColorPickerDialog(this, this, mPaint.getColor()).show();
        return true;
    case EMBOSS_MENU_ID:
        if (mPaint.getMaskFilter() != mEmboss) {
            mPaint.setMaskFilter(mEmboss);
        } else {
            mPaint.setMaskFilter(null);
        }
        return true;
    case BLUR_MENU_ID:
        if (mPaint.getMaskFilter() != mBlur) {
            mPaint.setMaskFilter(mBlur);
        } else {
            mPaint.setMaskFilter(null);
        }
        return true;
    case ERASE_MENU_ID:
        mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
        return true;
    case SRCATOP_MENU_ID:
        mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));
        mPaint.setAlpha(0x80);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.amazon.android.utils.Helpers.java

/**
 * Rounds the corners of an image.//ww  w. j  a  v a 2s  .  co m
 *
 * @param activity The activity.
 * @param raw      The raw bitmap image to round.
 * @param round    The radius for the round corners.
 * @return The rounded image.
 */
public static Bitmap roundCornerImage(Activity activity, Bitmap raw, float round) {

    int width = raw.getWidth();
    int height = raw.getHeight();
    Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    canvas.drawARGB(0, 0, 0, 0);

    final Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(ContextCompat.getColor(activity, android.R.color.black));

    final Rect rect = new Rect(0, 0, width, height);
    final RectF rectF = new RectF(rect);

    canvas.drawRoundRect(rectF, round, round, paint);

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

    return result;
}

From source file:org.opensilk.common.ui.util.ThemeUtils.java

public static Drawable colorizeBitmapDrawableCopy(Context context, int resId, int newColor) {
    final Drawable maskDrawable = context.getResources().getDrawable(resId);
    if (!(maskDrawable instanceof BitmapDrawable)) {
        return null;
    }/*from   w  w w  .j  a  v  a  2  s.c  o m*/

    final Bitmap maskBitmap = ((BitmapDrawable) maskDrawable).getBitmap();
    final int width = maskBitmap.getWidth();
    final int height = maskBitmap.getHeight();

    final Bitmap outBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(outBitmap);
    canvas.drawBitmap(maskBitmap, 0, 0, null);

    final Paint maskedPaint = new Paint();
    maskedPaint.setColor(newColor);
    maskedPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

    canvas.drawRect(0, 0, width, height, maskedPaint);

    return new BitmapDrawable(context.getResources(), outBitmap);
}

From source file:jp.envision.android.cloudfingerpaint.CloudFingerPaint.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    mPaint.setXfermode(null);/* w  w w.  ja va2 s .  c  om*/
    mPaint.setAlpha(0xFF);

    switch (item.getItemId()) {
    case COLOR_MENU_ID:
        new ColorPickerDialog(this, this, mPaint.getColor()).show();
        return true;
    case PRINT_MENU_ID:
        progressDialog = new ProgressDialog(this);
        progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progressDialog.setMessage("???s...");
        progressDialog.setCancelable(true);
        progressDialog.show();

        (new Thread(runnable)).start();

        return true;
    case EMBOSS_MENU_ID:
        if (mPaint.getMaskFilter() != mEmboss) {
            mPaint.setMaskFilter(mEmboss);
        } else {
            mPaint.setMaskFilter(null);
        }
        return true;
    case BLUR_MENU_ID:
        if (mPaint.getMaskFilter() != mBlur) {
            mPaint.setMaskFilter(mBlur);
        } else {
            mPaint.setMaskFilter(null);
        }
        return true;
    case ERASE_MENU_ID:
        mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
        return true;
    case SRCATOP_MENU_ID:
        mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));
        mPaint.setAlpha(0x80);
        return true;
    case CLEAR_MENU_ID:
        Log.d(TAG, "Clear canvas.");
        myView.clear_all();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.ibuildapp.romanblack.FanWallPlugin.data.Statics.java

/**
 * Sets the downloaded attached image./*from  w w w .j a v a  2 s .c o m*/
 *
 * @param fileName picture file path
 */
public static Bitmap publishPicture(String fileName) {
    Bitmap bitmap = null;
    try {

        if (!TextUtils.isEmpty(fileName)) {
            try {
                BitmapFactory.Options opts = new BitmapFactory.Options();
                opts.inJustDecodeBounds = true;
                BitmapFactory.decodeFile(fileName, opts);

                //Find the correct scale value. It should be the power of 2.
                int width = opts.outWidth, height = opts.outHeight;
                int scale = 1;
                while (true) {
                    if (width / 2 <= 150 || height / 2 <= 150) {
                        break;
                    }
                    width /= 2;
                    height /= 2;
                    scale *= 2;
                }
                BitmapFactory.Options opt = new BitmapFactory.Options();
                opt.inSampleSize = scale;

                bitmap = BitmapFactory.decodeFile(fileName, opt);
                int size = 0;
                if (bitmap.getHeight() > bitmap.getWidth()) {
                    size = bitmap.getWidth();
                } else {
                    size = bitmap.getHeight();
                }
                Bitmap output = Bitmap.createBitmap(size, size, Bitmap.Config.RGB_565);
                Canvas canvas = new Canvas(output);

                final int color = 0xff424242;
                final Paint paint = new Paint();
                final Rect rect = new Rect(0, 0, size, size);
                final RectF rectF = new RectF(rect);
                final float roundPx = 0;

                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;
            } catch (Exception e) {
                Log.w("", "");
            }
        }
    } catch (Exception ex) {

    }

    return null;
}

From source file:com.cooltechworks.views.ScratchImageView.java

public void setEraserMode() {

    getErasePaint().setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));

}