Search in sources :

Example 91 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project plaid by nickbutcher.

the class CutoutTextView method createBitmap.

private void createBitmap() {
    if (cutout != null && !cutout.isRecycled()) {
        cutout.recycle();
    }
    cutout = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
    cutout.setHasAlpha(true);
    Canvas cutoutCanvas = new Canvas(cutout);
    cutoutCanvas.drawColor(foregroundColor);
    // this is the magic – Clear mode punches out the bitmap
    textPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    cutoutCanvas.drawText(text, textX, textY, textPaint);
}
Also used : PorterDuffXfermode(android.graphics.PorterDuffXfermode) Canvas(android.graphics.Canvas)

Example 92 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project mobile-android by photo.

the class ImageResizer method getRoundedCornerBitmap.

/**
     * Get the bitmap with rounded corners. Taken from here
     * http://stackoverflow.com/a/3292810/527759
     * 
     * @param bitmap - bitmap to add corners to
     * @param pixels - corner radius
     * @return
     */
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
    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 = pixels;
    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 93 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project glitch-hq-android by tinyspeck.

the class BitmapUtil method MultiplyPaint.

public static void MultiplyPaint(Canvas cvs, Paint paint, Bitmap bmMask) {
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY));
    cvs.drawBitmap(bmMask, 0, 0, paint);
}
Also used : PorterDuffXfermode(android.graphics.PorterDuffXfermode)

Example 94 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project RippleEffect by traex.

the class RippleView method getCircleBitmap.

private Bitmap getCircleBitmap(final int radius) {
    final Bitmap output = Bitmap.createBitmap(originBitmap.getWidth(), originBitmap.getHeight(), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(output);
    final Paint paint = new Paint();
    final Rect rect = new Rect((int) (x - radius), (int) (y - radius), (int) (x + radius), (int) (y + radius));
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    canvas.drawCircle(x, y, radius, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(originBitmap, 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 95 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project Ushahidi_Android by ushahidi.

the class PhotoUtils method getRoundedCornerBitmap.

/**
	 * Create rounded corner bitmap from original bitmap.
	 * <p>
	 * Reference
	 * http://stackoverflow.com/questions/2459916/how-to-make-an-imageview
	 * -to-have-rounded-corners
	 * 
	 * @param input
	 *            Original bitmap.
	 * @param cornerRadius
	 *            Corner radius in pixel.
	 * @param w
	 * @param h
	 * @param squareTL
	 * @param squareTR
	 * @param squareBL
	 * @param squareBR
	 * @return
	 */
public static Bitmap getRoundedCornerBitmap(Bitmap input, float cornerRadius, int w, int h, boolean squareTL, boolean squareTR, boolean squareBL, boolean squareBR) {
    Bitmap output = Bitmap.createBitmap(w, h, Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, w, h);
    final RectF rectF = new RectF(rect);
    // make sure that our rounded corner is scaled appropriately
    final float roundPx = cornerRadius;
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
    // draw rectangles over the corners we want to be squared
    if (squareTL) {
        canvas.drawRect(0, 0, w / 2, h / 2, paint);
    }
    if (squareTR) {
        canvas.drawRect(w / 2, 0, w, h / 2, paint);
    }
    if (squareBL) {
        canvas.drawRect(0, h / 2, w / 2, h, paint);
    }
    if (squareBR) {
        canvas.drawRect(w / 2, h / 2, w, h, paint);
    }
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(input, 0, 0, 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)

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