Search in sources :

Example 76 with BitmapShader

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

the class TitanicTextView method createShader.

/**
     * Create the shader
     * draw the wave with current color for a background
     * repeat the bitmap horizontally, and clamp colors vertically
     */
private void createShader() {
    if (wave == null) {
        wave = getResources().getDrawable(R.drawable.titanic_wave_black);
    }
    int waveW = wave.getIntrinsicWidth();
    int waveH = wave.getIntrinsicHeight();
    Bitmap b = Bitmap.createBitmap(waveW, waveH, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(b);
    c.drawColor(getCurrentTextColor());
    wave.setBounds(0, 0, waveW, waveH);
    wave.draw(c);
    shader = new BitmapShader(b, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
    getPaint().setShader(shader);
    offsetY = (getHeight() - waveH) / 2;
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) BitmapShader(android.graphics.BitmapShader)

Example 77 with BitmapShader

use of android.graphics.BitmapShader in project UltimateRecyclerView by cymcsg.

the class CircularImageView method updateBitmapShader.

/**
	 * Re-initializes the shader texture used to fill in
	 * the Circle upon drawing.
	 */
public void updateBitmapShader() {
    if (image == null)
        return;
    shader = new BitmapShader(image, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    if (canvasSize != image.getWidth() || canvasSize != image.getHeight()) {
        Matrix matrix = new Matrix();
        float scale = (float) canvasSize / (float) image.getWidth();
        matrix.setScale(scale, scale);
        shader.setLocalMatrix(matrix);
    }
}
Also used : Matrix(android.graphics.Matrix) BitmapShader(android.graphics.BitmapShader)

Example 78 with BitmapShader

use of android.graphics.BitmapShader in project CircleImageView by hdodenhof.

the class CircleImageView method setup.

private void setup() {
    if (!mReady) {
        mSetupPending = true;
        return;
    }
    if (getWidth() == 0 && getHeight() == 0) {
        return;
    }
    if (mBitmap == null) {
        invalidate();
        return;
    }
    mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    mBitmapPaint.setAntiAlias(true);
    mBitmapPaint.setShader(mBitmapShader);
    mBorderPaint.setStyle(Paint.Style.STROKE);
    mBorderPaint.setAntiAlias(true);
    mBorderPaint.setColor(mBorderColor);
    mBorderPaint.setStrokeWidth(mBorderWidth);
    mFillPaint.setStyle(Paint.Style.FILL);
    mFillPaint.setAntiAlias(true);
    mFillPaint.setColor(mFillColor);
    mBitmapHeight = mBitmap.getHeight();
    mBitmapWidth = mBitmap.getWidth();
    mBorderRect.set(calculateBounds());
    mBorderRadius = Math.min((mBorderRect.height() - mBorderWidth) / 2.0f, (mBorderRect.width() - mBorderWidth) / 2.0f);
    mDrawableRect.set(mBorderRect);
    if (!mBorderOverlay && mBorderWidth > 0) {
        mDrawableRect.inset(mBorderWidth - 1.0f, mBorderWidth - 1.0f);
    }
    mDrawableRadius = Math.min(mDrawableRect.height() / 2.0f, mDrawableRect.width() / 2.0f);
    applyColorFilter();
    updateShaderMatrix();
    invalidate();
}
Also used : BitmapShader(android.graphics.BitmapShader)

Example 79 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 80 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)

Aggregations

BitmapShader (android.graphics.BitmapShader)137 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