Search in sources :

Example 96 with BitmapShader

use of android.graphics.BitmapShader in project Carbon by ZieIony.

the class RippleDrawableFroyo method updateMaskShaderIfNeeded.

/**
     * @return whether we need to use a mask
     */
private void updateMaskShaderIfNeeded() {
    if (mHasValidMask) {
        return;
    }
    final int maskType = getMaskType();
    if (maskType == MASK_UNKNOWN) {
        return;
    }
    mHasValidMask = true;
    final Rect bounds = getBounds();
    if (maskType == MASK_NONE || bounds.isEmpty()) {
        if (mMaskBuffer != null) {
            mMaskBuffer.recycle();
            mMaskBuffer = null;
            mMaskShader = null;
            mMaskCanvas = null;
        }
        mMaskMatrix = null;
        mMaskColorFilter = null;
        return;
    }
    // Ensure we have a correctly-sized buffer.
    if (mMaskBuffer == null || mMaskBuffer.getWidth() != bounds.width() || mMaskBuffer.getHeight() != bounds.height()) {
        if (mMaskBuffer != null) {
            mMaskBuffer.recycle();
        }
        mMaskBuffer = Bitmap.createBitmap(bounds.width(), bounds.height(), Bitmap.Config.ALPHA_8);
        mMaskShader = new BitmapShader(mMaskBuffer, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
        mMaskCanvas = new Canvas(mMaskBuffer);
    } else {
        mMaskBuffer.eraseColor(Color.TRANSPARENT);
    }
    if (mMaskMatrix == null) {
        mMaskMatrix = new Matrix();
    } else {
        mMaskMatrix.reset();
    }
    if (mMaskColorFilter == null) {
        mMaskColorFilter = new PorterDuffColorFilter(0, PorterDuff.Mode.SRC_IN);
    }
    // Draw the appropriate mask anchored to (0,0).
    final int left = bounds.left;
    final int top = bounds.top;
    mMaskCanvas.translate(-left, -top);
    if (maskType == MASK_EXPLICIT) {
        drawMask(mMaskCanvas);
    } else if (maskType == MASK_CONTENT) {
        drawContent(mMaskCanvas);
    }
    mMaskCanvas.translate(left, top);
}
Also used : Rect(android.graphics.Rect) Matrix(android.graphics.Matrix) Canvas(android.graphics.Canvas) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) BitmapShader(android.graphics.BitmapShader) Paint(android.graphics.Paint)

Example 97 with BitmapShader

use of android.graphics.BitmapShader in project remusic by aa112901.

the class RoundImageView method make.

private void make(Bitmap bitmap) {
    mBitmap = getCroppedRoundBitmap(bitmap, 255, 15);
    mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    mBitmapPaint.setAntiAlias(true);
    mBitmapPaint.setShader(mBitmapShader);
    mDrawableRect.set(0, 0, getWidth(), getHeight());
    mDrawableRadius = Math.min(mDrawableRect.height() / 2, mDrawableRect.width() / 2);
    mBitmapHeight = mBitmap.getHeight();
    mBitmapWidth = mBitmap.getWidth();
    updateShaderMatrix();
    invalidate();
}
Also used : BitmapShader(android.graphics.BitmapShader)

Example 98 with BitmapShader

use of android.graphics.BitmapShader in project Signal-Android by WhisperSystems.

the class RoundedCorners method round.

private Bitmap round(@NonNull BitmapPool pool, @Nullable Bitmap toRound) {
    if (toRound == null) {
        return null;
    }
    Bitmap result = pool.get(toRound.getWidth(), toRound.getHeight(), getSafeConfig(toRound));
    if (result == null) {
        result = Bitmap.createBitmap(toRound.getWidth(), toRound.getHeight(), getSafeConfig(toRound));
    }
    Canvas canvas = new Canvas(result);
    if (Config.RGB_565.equals(result.getConfig())) {
        Paint cornerPaint = new Paint();
        cornerPaint.setColor(colorHint);
        canvas.drawRect(0, 0, radius, radius, cornerPaint);
        canvas.drawRect(0, toRound.getHeight() - radius, radius, toRound.getHeight(), cornerPaint);
        canvas.drawRect(toRound.getWidth() - radius, 0, toRound.getWidth(), radius, cornerPaint);
        canvas.drawRect(toRound.getWidth() - radius, toRound.getHeight() - radius, toRound.getWidth(), toRound.getHeight(), cornerPaint);
    }
    Paint shaderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    shaderPaint.setShader(new BitmapShader(toRound, TileMode.CLAMP, TileMode.CLAMP));
    canvas.drawRoundRect(new RectF(0, 0, toRound.getWidth(), toRound.getHeight()), radius, radius, shaderPaint);
    return result;
}
Also used : RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) BitmapShader(android.graphics.BitmapShader)

Example 99 with BitmapShader

use of android.graphics.BitmapShader in project platform_frameworks_base by android.

the class UserIconDrawable method setIcon.

public UserIconDrawable setIcon(Bitmap icon) {
    if (mUserDrawable != null) {
        mUserDrawable.setCallback(null);
        mUserDrawable = null;
    }
    mUserIcon = icon;
    if (mUserIcon == null) {
        mIconPaint.setShader(null);
        mBitmap = null;
    } else {
        mIconPaint.setShader(new BitmapShader(icon, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
    }
    onBoundsChange(getBounds());
    return this;
}
Also used : BitmapShader(android.graphics.BitmapShader)

Example 100 with BitmapShader

use of android.graphics.BitmapShader in project NotificationPeekPort by lzanita09.

the class NotificationPeekViewUtils method getRoundedShape.

/**
     * Get rounded icon from the Bitmap object, with shade. The shade will only be drawn if
     * the Bitmap is larger than the ImageView's size.
     *
     * @param resources         Resources object for getting size and color.
     * @param scaleBitmapImage  Source Bitmap.
     * @return                  Rounded BitmapDrawable with shade (if possible).
     */
public static Drawable getRoundedShape(Resources resources, Bitmap scaleBitmapImage) {
    final int shadowSize = resources.getDimensionPixelSize(R.dimen.shadow_size);
    final int shadowColor = resources.getColor(R.color.background_color);
    int targetWidth = scaleBitmapImage.getWidth();
    int targetHeight = scaleBitmapImage.getHeight();
    Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setDither(true);
    Paint shadowPaint = new Paint(paint);
    RectF rectF = new RectF(0, 0, targetWidth, targetHeight);
    Canvas canvas = new Canvas(targetBitmap);
    final BitmapShader shader = new BitmapShader(scaleBitmapImage, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    paint.setShader(shader);
    // Only apply shadow if the icon is large enough.
    if (scaleBitmapImage.getWidth() > resources.getDimensionPixelSize(R.dimen.notification_icon_size)) {
        rectF.inset(shadowSize, shadowSize);
        shadowPaint.setShadowLayer(shadowSize, 0f, 0f, shadowColor);
        shadowPaint.setColor(Color.BLACK);
        canvas.drawOval(rectF, shadowPaint);
    }
    canvas.drawOval(rectF, paint);
    return new BitmapDrawable(resources, targetBitmap);
}
Also used : RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapShader(android.graphics.BitmapShader) Paint(android.graphics.Paint)

Aggregations

BitmapShader (android.graphics.BitmapShader)135 Bitmap (android.graphics.Bitmap)86 Paint (android.graphics.Paint)69 Canvas (android.graphics.Canvas)60 Matrix (android.graphics.Matrix)20 BitmapDrawable (android.graphics.drawable.BitmapDrawable)15 RectF (android.graphics.RectF)14 ShapeDrawable (android.graphics.drawable.ShapeDrawable)14 AnimationDrawable (android.graphics.drawable.AnimationDrawable)13 ClipDrawable (android.graphics.drawable.ClipDrawable)13 Drawable (android.graphics.drawable.Drawable)13 LayerDrawable (android.graphics.drawable.LayerDrawable)13 Rect (android.graphics.Rect)9 Shader (android.graphics.Shader)8 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)6 StateListDrawable (android.graphics.drawable.StateListDrawable)4 Point (android.graphics.Point)3 SuppressLint (android.annotation.SuppressLint)2 ColorMatrix (android.graphics.ColorMatrix)2 TypedArray (android.content.res.TypedArray)1