Search in sources :

Example 1 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project photo-picker-plus-android by chute.

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 2 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project ENViews by codeestX.

the class ENLoadingView method clearCanvas.

private void clearCanvas() {
    Canvas canvas = surfaceHolder.lockCanvas();
    if (canvas == null)
        return;
    mPaint[0].setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.CLEAR));
    canvas.drawPaint(mPaint[0]);
    mPaint[0].setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.DST_OVER));
    surfaceHolder.unlockCanvasAndPost(canvas);
    mThread.interrupt();
    mThread = null;
}
Also used : PorterDuffXfermode(android.graphics.PorterDuffXfermode) Canvas(android.graphics.Canvas)

Example 3 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project MaterialShowcaseView by deano2390.

the class MaterialShowcaseView method onDraw.

/**
     * Interesting drawing stuff.
     * We draw a block of semi transparent colour to fill the whole screen then we draw of transparency
     * to create a circular "viewport" through to the underlying content
     *
     * @param canvas
     */
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    // don't bother drawing if we're not ready
    if (!mShouldRender)
        return;
    // get current dimensions
    final int width = getMeasuredWidth();
    final int height = getMeasuredHeight();
    // don't bother drawing if there is nothing to draw on
    if (width <= 0 || height <= 0)
        return;
    // build a new canvas if needed i.e first pass or new dimensions
    if (mBitmap == null || mCanvas == null || mOldHeight != height || mOldWidth != width) {
        if (mBitmap != null)
            mBitmap.recycle();
        mBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        mCanvas = new Canvas(mBitmap);
    }
    // save our 'old' dimensions
    mOldWidth = width;
    mOldHeight = height;
    // clear canvas
    mCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
    // draw solid background
    mCanvas.drawColor(mMaskColour);
    // Prepare eraser Paint if needed
    if (mEraser == null) {
        mEraser = new Paint();
        mEraser.setColor(0xFFFFFFFF);
        mEraser.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
        mEraser.setFlags(Paint.ANTI_ALIAS_FLAG);
    }
    // draw (erase) shape
    mShape.draw(mCanvas, mEraser, mXPosition, mYPosition, mShapePadding);
    // Draw the bitmap on our views  canvas.
    canvas.drawBitmap(mBitmap, 0, 0, null);
}
Also used : PorterDuffXfermode(android.graphics.PorterDuffXfermode) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) Point(android.graphics.Point) Paint(android.graphics.Paint)

Example 4 with PorterDuffXfermode

use of android.graphics.PorterDuffXfermode in project UltimateAndroid by cymcsg.

the class RippleDrawable method draw.

@Override
public void draw(Canvas canvas) {
    final boolean hasMask = mMask != null;
    //TODO if contentDrawable is not null
    final boolean drawNonMaskContent = mContent != null;
    final boolean drawMask = hasMask && mMask.getOpacity() != PixelFormat.OPAQUE;
    final Rect bounds = getDirtyBounds();
    final int saveCount = canvas.save(Canvas.CLIP_SAVE_FLAG);
    canvas.clipRect(bounds);
    // If we have content, draw it into a layer first.
    if (drawNonMaskContent) {
        drawContentLayer(canvas, bounds, SRC_OVER);
    }
    // Next, try to draw the ripples (into a layer if necessary). If we need
    // to mask against the underlying content, set the xfermode to SRC_ATOP.
    final PorterDuffXfermode xfermode = (hasMask || !drawNonMaskContent) ? SRC_OVER : SRC_ATOP;
    // If we have a background and a non-opaque mask, draw the masking layer.
    final int backgroundLayer = drawBackgroundLayer(canvas, bounds, xfermode, drawMask);
    if (backgroundLayer >= 0) {
        if (drawMask) {
            drawMaskingLayer(canvas, bounds, DST_IN);
        }
        canvas.restoreToCount(backgroundLayer);
    }
    // If we have ripples and a non-opaque mask, draw the masking layer.
    final int rippleLayer = drawRippleLayer(canvas, bounds, xfermode);
    if (rippleLayer >= 0) {
        if (drawMask) {
            drawMaskingLayer(canvas, bounds, DST_IN);
        }
        canvas.restoreToCount(rippleLayer);
    }
    // least draw a color so that hardware invalidation works correctly.
    if (mNeedsDraw) {
        canvas.drawColor(Color.TRANSPARENT);
        // Request another draw so we can avoid adding a transparent layer
        // during the next display list refresh.
        invalidateSelf();
    }
    mNeedsDraw = false;
    canvas.restoreToCount(saveCount);
}
Also used : Rect(android.graphics.Rect) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Paint(android.graphics.Paint)

Example 5 with PorterDuffXfermode

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

the class WallpaperManager method generateBitmap.

static Bitmap generateBitmap(Context context, Bitmap bm, int width, int height) {
    if (bm == null) {
        return null;
    }
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics metrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(metrics);
    bm.setDensity(metrics.noncompatDensityDpi);
    if (width <= 0 || height <= 0 || (bm.getWidth() == width && bm.getHeight() == height)) {
        return bm;
    }
    // This is the final bitmap we want to return.
    try {
        Bitmap newbm = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        newbm.setDensity(metrics.noncompatDensityDpi);
        Canvas c = new Canvas(newbm);
        Rect targetRect = new Rect();
        targetRect.right = bm.getWidth();
        targetRect.bottom = bm.getHeight();
        int deltaw = width - targetRect.right;
        int deltah = height - targetRect.bottom;
        if (deltaw > 0 || deltah > 0) {
            // We need to scale up so it covers the entire area.
            float scale;
            if (deltaw > deltah) {
                scale = width / (float) targetRect.right;
            } else {
                scale = height / (float) targetRect.bottom;
            }
            targetRect.right = (int) (targetRect.right * scale);
            targetRect.bottom = (int) (targetRect.bottom * scale);
            deltaw = width - targetRect.right;
            deltah = height - targetRect.bottom;
        }
        targetRect.offset(deltaw / 2, deltah / 2);
        Paint paint = new Paint();
        paint.setFilterBitmap(true);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
        c.drawBitmap(bm, null, targetRect, paint);
        bm.recycle();
        c.setBitmap(null);
        return newbm;
    } catch (OutOfMemoryError e) {
        Log.w(TAG, "Can't generate default bitmap", e);
        return bm;
    }
}
Also used : Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) DisplayMetrics(android.util.DisplayMetrics) Paint(android.graphics.Paint) WindowManager(android.view.WindowManager)

Aggregations

PorterDuffXfermode (android.graphics.PorterDuffXfermode)148 Paint (android.graphics.Paint)124 Canvas (android.graphics.Canvas)101 Bitmap (android.graphics.Bitmap)90 Rect (android.graphics.Rect)64 RectF (android.graphics.RectF)49 SuppressLint (android.annotation.SuppressLint)9 LinearGradient (android.graphics.LinearGradient)9 Matrix (android.graphics.Matrix)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