Search in sources :

Example 51 with LinearGradient

use of android.graphics.LinearGradient in project AndroidUtilCode by Blankj.

the class ImageUtils method addReflection.

/**
     * 添加倒影
     *
     * @param src              源图片的
     * @param reflectionHeight 倒影高度
     * @param recycle          是否回收
     * @return 带倒影图片
     */
public static Bitmap addReflection(Bitmap src, int reflectionHeight, boolean recycle) {
    if (isEmptyBitmap(src))
        return null;
    // 原图与倒影之间的间距
    final int REFLECTION_GAP = 0;
    int srcWidth = src.getWidth();
    int srcHeight = src.getHeight();
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    Bitmap reflectionBitmap = Bitmap.createBitmap(src, 0, srcHeight - reflectionHeight, srcWidth, reflectionHeight, matrix, false);
    Bitmap ret = Bitmap.createBitmap(srcWidth, srcHeight + reflectionHeight, src.getConfig());
    Canvas canvas = new Canvas(ret);
    canvas.drawBitmap(src, 0, 0, null);
    canvas.drawBitmap(reflectionBitmap, 0, srcHeight + REFLECTION_GAP, null);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    LinearGradient shader = new LinearGradient(0, srcHeight, 0, ret.getHeight() + REFLECTION_GAP, 0x70FFFFFF, 0x00FFFFFF, Shader.TileMode.MIRROR);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.DST_IN));
    canvas.drawRect(0, srcHeight + REFLECTION_GAP, srcWidth, ret.getHeight(), paint);
    if (!reflectionBitmap.isRecycled())
        reflectionBitmap.recycle();
    if (recycle && !src.isRecycled())
        src.recycle();
    return ret;
}
Also used : LinearGradient(android.graphics.LinearGradient) Bitmap(android.graphics.Bitmap) ColorMatrix(android.graphics.ColorMatrix) Matrix(android.graphics.Matrix) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 52 with LinearGradient

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

the class ShimmerViewHelper method resetLinearGradient.

private void resetLinearGradient() {
    // our gradient is a simple linear gradient from textColor to reflectionColor. its axis is at the center
    // when it's outside of the view, the outer color (textColor) will be repeated (Shader.TileMode.CLAMP)
    // initially, the linear gradient is positioned on the left side of the view
    linearGradient = new LinearGradient(-view.getWidth(), 0, 0, 0, new int[] { primaryColor, reflectionColor, primaryColor }, new float[] { 0, 0.5f, 1 }, Shader.TileMode.CLAMP);
    paint.setShader(linearGradient);
}
Also used : LinearGradient(android.graphics.LinearGradient)

Example 53 with LinearGradient

use of android.graphics.LinearGradient in project Lightning-Browser by anthonycr.

the class Utils method drawTrapezoid.

/**
     * Draws the trapezoid background for the horizontal tabs on a canvas object using
     * the specified color.
     *
     * @param canvas the canvas to draw upon
     * @param color  the color to use to draw the tab
     */
public static void drawTrapezoid(@NonNull Canvas canvas, int color, boolean withShader) {
    Paint paint = new Paint();
    paint.setColor(color);
    paint.setStyle(Paint.Style.FILL);
    //        paint.setFilterBitmap(true);
    paint.setAntiAlias(true);
    paint.setDither(true);
    if (withShader) {
        paint.setShader(new LinearGradient(0, 0.9f * canvas.getHeight(), 0, canvas.getHeight(), color, mixTwoColors(Color.BLACK, color, 0.5f), Shader.TileMode.CLAMP));
    } else {
        paint.setShader(null);
    }
    int width = canvas.getWidth();
    int height = canvas.getHeight();
    double radians = Math.PI / 3;
    int base = (int) (height / Math.tan(radians));
    Path wallpath = new Path();
    wallpath.reset();
    wallpath.moveTo(0, height);
    wallpath.lineTo(width, height);
    wallpath.lineTo(width - base, 0);
    wallpath.lineTo(base, 0);
    wallpath.close();
    canvas.drawPath(wallpath, paint);
}
Also used : Path(android.graphics.Path) LinearGradient(android.graphics.LinearGradient) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Example 54 with LinearGradient

use of android.graphics.LinearGradient in project ABPlayer by winkstu.

the class ColorPickerView method drawHuePanel.

private void drawHuePanel(Canvas canvas) {
    final RectF rect = mHueRect;
    if (BORDER_WIDTH_PX > 0) {
        mBorderPaint.setColor(mBorderColor);
        canvas.drawRect(rect.left - BORDER_WIDTH_PX, rect.top - BORDER_WIDTH_PX, rect.right + BORDER_WIDTH_PX, rect.bottom + BORDER_WIDTH_PX, mBorderPaint);
    }
    if (mHueShader == null) {
        mHueShader = new LinearGradient(rect.left, rect.top, rect.left, rect.bottom, buildHueColorArray(), null, TileMode.CLAMP);
        mHuePaint.setShader(mHueShader);
    }
    canvas.drawRect(rect, mHuePaint);
    float rectHeight = 4 * mDensity / 2;
    Point p = hueToPoint(mHue);
    RectF r = new RectF();
    r.left = rect.left - RECTANGLE_TRACKER_OFFSET;
    r.right = rect.right + RECTANGLE_TRACKER_OFFSET;
    r.top = p.y - rectHeight;
    r.bottom = p.y + rectHeight;
    canvas.drawRoundRect(r, 2, 2, mHueTrackerPaint);
}
Also used : RectF(android.graphics.RectF) LinearGradient(android.graphics.LinearGradient) Point(android.graphics.Point)

Example 55 with LinearGradient

use of android.graphics.LinearGradient in project dobby-android by InceptAi.

the class CircularGauge method onDraw.

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    float padding = getStrokeWidth();
    float size = getWidth() < getHeight() ? getWidth() : getHeight();
    float width = size - (2 * padding);
    float height = size - (2 * padding);
    float radius = (width < height ? width / 2 : height / 2);
    float rectLeft = (getWidth() - (2 * padding)) / 2 - radius + padding;
    float rectTop = (getHeight() - (2 * padding)) / 2 - radius + padding;
    float rectRight = (getWidth() - (2 * padding)) / 2 - radius + padding + width;
    float rectBottom = (getHeight() - (2 * padding)) / 2 - radius + padding + height;
    mRect.set(rectLeft, rectTop, rectRight, rectBottom);
    mPaint.setColor(mStrokeColor);
    mPaint.setShader(null);
    mPaint.setStrokeWidth(mBaselineStrokeWidth);
    canvas.drawArc(mRect, mStartAngle, mSweepAngle, false, mPaint);
    mPaint.setColor(mPointStartColor);
    mPaint.setShader(new LinearGradient(getWidth(), getHeight(), 0, 0, mPointEndColor, mPointStartColor, Shader.TileMode.CLAMP));
    /* Switch to mStrokeWidth when showing the real data */
    mPaint.setStrokeWidth(mStrokeWidth);
    if (mPointSize > 0) {
        // if size of pointer is defined
        if (mCurrentValueInAngle > mStartAngle + mPointSize / 2) {
            canvas.drawArc(mRect, mCurrentValueInAngle - mPointSize / 2, mPointSize, false, mPaint);
        } else {
            // to avoid exceeding start/zero point
            canvas.drawArc(mRect, mCurrentValueInAngle, mPointSize, false, mPaint);
        }
    } else {
        // draw from start point to value point (long pointer)
        if (// use non-zero default value for start point (to avoid lack of pointer for start/zero value)
        mValue == mStartValue)
            canvas.drawArc(mRect, mStartAngle, DEFAULT_LONG_POINTER_SIZE, false, mPaint);
        else
            canvas.drawArc(mRect, mStartAngle, mCurrentValueInAngle - mStartAngle, false, mPaint);
    }
    if (mDividerSize > 0) {
        mPaint.setColor(mDividerColor);
        mPaint.setShader(null);
        int i = mDividerDrawFirst ? 0 : 1;
        int max = mDividerDrawLast ? mDividersCount + 1 : mDividersCount;
        for (; i < max; i++) {
            canvas.drawArc(mRect, mStartAngle + i * mDividerStepAngle, mDividerSize, false, mPaint);
        }
    }
}
Also used : LinearGradient(android.graphics.LinearGradient) Paint(android.graphics.Paint)

Aggregations

LinearGradient (android.graphics.LinearGradient)123 Paint (android.graphics.Paint)70 RectF (android.graphics.RectF)38 RadialGradient (android.graphics.RadialGradient)27 Canvas (android.graphics.Canvas)22 Rect (android.graphics.Rect)21 Path (android.graphics.Path)18 Shader (android.graphics.Shader)18 Bitmap (android.graphics.Bitmap)15 Matrix (android.graphics.Matrix)15 Point (android.graphics.Point)13 SweepGradient (android.graphics.SweepGradient)12 PorterDuffXfermode (android.graphics.PorterDuffXfermode)9 ShapeDrawable (android.graphics.drawable.ShapeDrawable)9 SuppressLint (android.annotation.SuppressLint)6 ComposeShader (android.graphics.ComposeShader)6 PaintDrawable (android.graphics.drawable.PaintDrawable)5 RectShape (android.graphics.drawable.shapes.RectShape)5 ColorMatrix (android.graphics.ColorMatrix)3 PointF (android.graphics.PointF)3