Java 类android.graphics.Shader 实例源码

项目:Oblique    文件:ObliqueView.java   
private void setupBitmap(ImageView imageView, float width, float height) {
    Drawable drawable = imageView.getDrawable();
    if (drawable == null) {
        return;
    }
    try {
        bitmap = (drawable instanceof BitmapDrawable) ?
                ((BitmapDrawable) drawable).getBitmap() :
                Bitmap.createBitmap(drawable.getIntrinsicWidth(),
                        drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (bitmap == null) {
        imageView.invalidate();
        return;
    }
    paint = new Paint(ANTI_ALIAS_FLAG);
    bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    paint.setShader(bitmapShader);
    if (imageView.getScaleType() != ImageView.ScaleType.CENTER_CROP && imageView.getScaleType() != ImageView.ScaleType.FIT_XY) {
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    }
    bitmapShader.setLocalMatrix(setUpScaleType(bitmap, imageView, width, height));
    imageView.invalidate();
}
项目:VirtualHook    文件:ShimmerViewHelper.java   
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);
    }
项目:SimpleDialogFragments    文件:ColorWheelView.java   
protected void updateColorDependant(boolean hsvChanged, boolean hueChanged){
    if (hueChanged) {
        Shader base = new LinearGradient(A.x, A.y, (B.x + C.x) / 2, (B.y + C.y) / 2,
                Color.HSVToColor(new float[]{mColor.hue(), 1, 1}), Color.BLACK, Shader.TileMode.CLAMP);
        Shader light = new LinearGradient((A.x + C.x) / 2, (A.y + C.y) / 2, B.x, B.y,
                Color.BLACK, Color.WHITE, Shader.TileMode.CLAMP);
        Shader both = new ComposeShader(base, light, PorterDuff.Mode.ADD);
        paint.setShader(both);
    }
    if (hsvChanged) {
        dotPaint.setColor(mColor.inverted().rgb());
        dot = new PointF(
                C.x + (B.x - C.x + (A.x - B.x) * mColor.sat()) * mColor.val(),
                C.y + (B.y - C.y + (A.y - B.y) * mColor.sat()) * mColor.val());
    }
}
项目:spline    文件:SaturationValueDrawable.java   
@Override
public void draw(Canvas canvas) {
    Rect b = getBounds();
    int height = b.height();
    int width = b.width();

    Paint valuePaint = new Paint();
    valuePaint.setShader(
            new LinearGradient(0, mInset, 0, height - mInset,
                    Color.WHITE, Color.BLACK, Shader.TileMode.CLAMP)
    );

    float hsv[] = {mHue, 1.0f, 1.0f};
    int pureHue = Color.HSVToColor(hsv);
    Paint saturationPaint = new Paint();
    saturationPaint.setShader(
            new LinearGradient(mInset, 0, width - mInset, 0,
                    Color.WHITE, pureHue, Shader.TileMode.CLAMP)
    );
    saturationPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY));

    canvas.drawRect(b, valuePaint);
    canvas.drawRect(b, saturationPaint);
}
项目:BubbleView    文件:BubbleDrawable.java   
public BubbleDrawable(Builder builder) {
    triangleWidth = builder.triangleWidth;
    triangleHeight = builder.triangleHeight;
    offset = builder.offset;
    radius = builder.radius;
    orientation = builder.orientation;
    bitmap = builder.bitmap;
    borderWidth = builder.borderWidth;
    centerArrow = builder.centerArrow;
    shadowRadius = builder.shadowRadius;
    shadowColor = builder.shadowColor;

    borderPaint.setStyle(Paint.Style.STROKE);
    borderPaint.setStrokeCap(Paint.Cap.ROUND);
    borderPaint.setColor(builder.borderColor);

    leftTopRadiusRect = new RectF();
    rightBottomRadiusRect = new RectF();
    leftBottomRadiusRect = new RectF();
    rightTopRadiusRect = new RectF();

    bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    bitmapPaint.setShader(bitmapShader);
}
项目:xlight_android_native    文件:SVBar.java   
/**
 * Set the bar color. <br>
 * <br>
 * Its discouraged to use this method.
 * 
 * @param color
 */
public void setColor(int color) {
    int x1, y1;
    if(mOrientation) {
        x1 = (mBarLength + mBarPointerHaloRadius);
        y1 = mBarThickness;
    }        else {
        x1 = mBarThickness;
        y1 = (mBarLength + mBarPointerHaloRadius);
    }

    Color.colorToHSV(color, mHSVColor);
    shader = new LinearGradient(mBarPointerHaloRadius, 0,
            x1, y1, new int[] {Color.WHITE, color, Color.BLACK}, null,
            Shader.TileMode.CLAMP);
    mBarPaint.setShader(shader);
    calculateColor(mBarPointerPosition);
    mBarPointerPaint.setColor(mColor);
    if (mPicker != null) {
        mPicker.setNewCenterColor(mColor);
        if(mPicker.hasOpacityBar())
            mPicker.changeOpacityBarColor(mColor);
    }
    invalidate();
}
项目:Picasso-transformations    文件:RoundedCornersTransformation.java   
@Override public Bitmap transform(Bitmap source) {

    int width = source.getWidth();
    int height = source.getHeight();

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
    drawRoundRect(canvas, paint, width, height);
    source.recycle();

    return bitmap;
  }
项目:OpenEyesReading-android    文件:CircleImageView.java   
private void setupView() {
    if (!mReady) {
        mSetupPending = true;
        return;
    }
    if (mBitmap == null) 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);
    mBitmapHeight = mBitmap.getHeight();
    mBitmapWidth = mBitmap.getWidth();
    mBorderRect.set(0, 0, getWidth(), getHeight());
    mDrawableRect.set(mBorderRect);
    mDrawableRadius = Math.min(mDrawableRect.height() / 2, mDrawableRect.width() / 2);
    updateShaderMatrix();
    invalidate();
}
项目:FriskyImage    文件:FriskyShimmerViewHelper.java   
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);
    }
项目:ShimmerLayout    文件:ShimmerLayout.java   
private Bitmap getSourceMaskBitmap() {
    if (sourceMaskBitmap != null) {
        return sourceMaskBitmap;
    }

    int width = maskRect.width();
    int height = getHeight();

    final int edgeColor = reduceColorAlphaValueToZero(shimmerColor);
    LinearGradient gradient = new LinearGradient(
            -maskRect.left, 0,
            width + maskRect.left, 0,
            new int[]{edgeColor, shimmerColor, shimmerColor, edgeColor},
            getGradientColorDistribution(),
            Shader.TileMode.CLAMP);
    Paint paint = new Paint();
    paint.setShader(gradient);

    sourceMaskBitmap = createBitmap(width, height);
    Canvas canvas = new Canvas(sourceMaskBitmap);
    canvas.rotate(shimmerAngle, width / 2, height / 2);
    canvas.drawRect(-maskRect.left, maskRect.top, width + maskRect.left, maskRect.bottom, paint);

    return sourceMaskBitmap;
}
项目:microMathematics    文件:SVBar.java   
/**
 * Set the bar color. <br>
 * <br>
 * Its discouraged to use this method.
 * 
 * @param color
 */
public void setColor(int color) {
    int x1, y1;
    if (mOrientation) {
        x1 = (mBarLength + mBarPointerHaloRadius);
        y1 = mBarThickness;
    } else {
        x1 = mBarThickness;
        y1 = (mBarLength + mBarPointerHaloRadius);
    }

    Color.colorToHSV(color, mHSVColor);
    shader = new LinearGradient(mBarPointerHaloRadius, 0, x1, y1,
            new int[] { Color.WHITE, color, Color.BLACK }, null,
            Shader.TileMode.CLAMP);
    mBarPaint.setShader(shader);
    calculateColor(mBarPointerPosition);
    mBarPointerPaint.setColor(mColor);
    if (mPicker != null) {
        mPicker.setNewCenterColor(mColor);
        if (mPicker.hasOpacityBar())
            mPicker.changeOpacityBarColor(mColor);
    }
    invalidate();
}
项目:app_secompufscar    文件:Pessoa.java   
public Bitmap getFotoBitmap(Context context) {

        Bitmap image;

        if (this.foto != null) {
            image = BitmapFactory.decodeByteArray(this.foto, 0, this.foto.length);
        } else {
            image = BitmapFactory.decodeResource(context.getResources(), R.drawable.pessoa_foto_default);
        }

        Bitmap imageRounded = Bitmap.createBitmap(image.getWidth(), image.getHeight(), image.getConfig());
        Canvas canvas = new Canvas(imageRounded);
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setShader(new BitmapShader(image, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
        canvas.drawRoundRect((new RectF(0, 0, image.getWidth(), image.getHeight())), image.getWidth() / 2, image.getWidth() / 2, paint);// Round Image Corner 100 100 100 100

        return imageRounded;
    }
项目:HoldingButton    文件:HoldingDrawable.java   
public void setCancelIcon(Bitmap bitmap) {
    if (bitmap != null) {
        mCancelIconWidth = bitmap.getWidth();
        mCancelIconHeight = bitmap.getHeight();
        mCancelIconShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
        mCancelIconShader.setLocalMatrix(mCancelIconMatrix);
        mCancelIconPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mCancelIconPaint.setShader(mCancelIconShader);
        mCancelIconPaint.setColorFilter(new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN));

        invalidateSelf();
    } else {
        mCancelIconWidth = 0;
        mCancelIconHeight = 0;
        mCancelIconMatrix = null;
        mCancelIconPaint = null;
    }
}
项目:RLibrary    文件:ShimmerViewHelper.java   
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);
    }
项目:app_secompufscar    文件:Instagram.java   
public static Bitmap getImageRound(byte[] imageByte) {

        Bitmap image;

        image = BitmapFactory.decodeByteArray(imageByte, 0, imageByte.length);

        //TODO: Verificar se o formato da imagem está correto;
        Bitmap imageRounded = Bitmap.createBitmap(image.getWidth(), image.getHeight(), image.getConfig());
        Canvas canvas = new Canvas(imageRounded);
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setShader(new BitmapShader(image, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
        canvas.drawRoundRect((new RectF(0, 0, image.getWidth(), image.getHeight())), image.getWidth() / 2, image.getWidth() / 2, paint);// Round Image Corner 100 100 100 100

        return imageRounded;
    }
项目:DMAudioStreamer    文件:CircleImageView.java   
private void updateShader() {
    if (image == null)
        return;

    // Crop Center Image
    image = cropBitmap(image);

    // Create Shader
    BitmapShader shader = new BitmapShader(image, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);

    // Center Image in Shader
    Matrix matrix = new Matrix();
    matrix.setScale((float) canvasSize / (float) image.getWidth(), (float) canvasSize / (float) image.getHeight());
    shader.setLocalMatrix(matrix);

    // Set Shader in Paint
    paint.setShader(shader);
}
项目:spinify_android    文件:TouchImageView.java   
@Override
protected void onDraw(Canvas canvas) {
    onDrawReady = true;
    imageRenderedAtLeastOnce = true;
    if (delayedZoomVariables != null) {
        setZoom(delayedZoomVariables.scale, delayedZoomVariables.focusX, delayedZoomVariables.focusY, delayedZoomVariables.scaleType);
        delayedZoomVariables = null;
    }
    super.onDraw(canvas);
    if (!zooming) {
        buildDrawingCache();
    } else {

        bitmap = getDrawingCache();
        shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);

        paint = new Paint();
        paint.setShader(shader);
        eMatrix.reset();
        eMatrix.postScale(2f, 2f, zoomPos.x, zoomPos.y);
        paint.getShader().setLocalMatrix(eMatrix);
        canvas.drawCircle(zoomPos.x, zoomPos.y, sizeOfMagnifier, paint);
    }
}
项目:android-project-gallery    文件:RoundedDrawable.java   
public RoundedDrawable(Bitmap bitmap)
{

    mBitmapWidth = bitmap.getWidth();
    mBitmapHeight = bitmap.getHeight();
    mBitmapRect.set(0, 0, mBitmapWidth, mBitmapHeight);

    mBitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    mBitmapShader.setLocalMatrix(mShaderMatrix);

    mBitmapPaint = new Paint();
    mBitmapPaint.setStyle(Paint.Style.FILL);
    mBitmapPaint.setAntiAlias(true);
    mBitmapPaint.setShader(mBitmapShader);

    mBorderPaint = new Paint();
    mBorderPaint.setStyle(Paint.Style.STROKE);
    mBorderPaint.setAntiAlias(true);
    mBorderPaint.setColor(mBorderColor.getColorForState(getState(), DEFAULT_BORDER_COLOR));
    mBorderPaint.setStrokeWidth(mBorderWidth);
}
项目:SnakeViewMaker    文件:RoundTransformation.java   
@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
    if (null == toTransform)
        return null;

    // outWidth is the width of the target ImageView,and the same to outHeight
    // all the ori bitmaps loaded may have different size, in order to the clipped
    // the bitmaps have the same size and shape,we use the target ImageView's size
    // to create bitmaps
    updateDrawBound(toTransform.getWidth(), toTransform.getHeight(), outWidth, outHeight);

    Bitmap bitmap = pool.get(drawWidth, drawHeight, Bitmap.Config.ARGB_8888);
    if (bitmap == null) {
        bitmap = Bitmap.createBitmap(drawWidth, drawHeight, Bitmap.Config.ARGB_8888);
    }
    bitmap.setHasAlpha(true);
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setShader(new BitmapShader(toTransform, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
    drawRoundRect(canvas, paint);
    return bitmap;
}
项目:HeroVideo-master    文件:CircleImageView.java   
private void setup()
{

    if (!mReady)
    {
        mSetupPending = true;
        return;
    }

    if (mBitmap == null)
    {
        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);

    mBitmapHeight = mBitmap.getHeight();
    mBitmapWidth = mBitmap.getWidth();

    mBorderRect.set(0, 0, getWidth(), getHeight());
    mBorderRadius = Math.min((mBorderRect.height() - mBorderWidth) / 2, (mBorderRect.width() - mBorderWidth) / 2);

    mDrawableRect.set(mBorderRect);
    if (!mBorderOverlay)
    {
        mDrawableRect.inset(mBorderWidth, mBorderWidth);
    }
    mDrawableRadius = Math.min(mDrawableRect.height() / 2, mDrawableRect.width() / 2);

    updateShaderMatrix();
    invalidate();
}
项目:Building-Android-UIs-with-Custom-Views    文件:OwnCustomView.java   
@Override
protected void onDraw(Canvas canvas) {
    if (firstDraw) {
        LinearGradient lg = new LinearGradient(0, 0, getWidth(), getHeight(),
                colorArray, null, Shader.TileMode.CLAMP);

        backgroundPaint.setShader(lg);
        firstDraw = false;
    }

    canvas.drawRect(0, 0, getWidth(), getHeight(), backgroundPaint);
    super.onDraw(canvas);
}
项目:Mire    文件:NoiseEffect.java   
public NoiseEffect(Bitmap bitmap, int grainFPS, float scale) {
    super(bitmap, 0, 0);
    shader = new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
    matrix = new Matrix();

    shader.setLocalMatrix(matrix);
    paint.setShader(shader);
    paint.setAlpha(144);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SCREEN));
    lastGrainOffset = System.currentTimeMillis();
    this.grainFPS = grainFPS;
    this.scale=scale;
}
项目:cwac-crossport    文件:CircularBorderDrawable.java   
/**
 * Creates a vertical {@link LinearGradient}
 * @return
 */
private Shader createGradientShader() {
  final Rect rect = mRect;
  copyBounds(rect);

  final float borderRatio = mBorderWidth / rect.height();

  final int[] colors = new int[6];
  colors[0] = ColorUtils.compositeColors(mTopOuterStrokeColor, mCurrentBorderTintColor);
  colors[1] = ColorUtils.compositeColors(mTopInnerStrokeColor, mCurrentBorderTintColor);
      colors[2] = ColorUtils.compositeColors(
          ColorUtils.setAlphaComponent(mTopInnerStrokeColor, 0), mCurrentBorderTintColor);
      colors[3] = ColorUtils.compositeColors(
          ColorUtils.setAlphaComponent(mBottomInnerStrokeColor, 0), mCurrentBorderTintColor);
  colors[4] = ColorUtils.compositeColors(mBottomInnerStrokeColor, mCurrentBorderTintColor);
  colors[5] = ColorUtils.compositeColors(mBottomOuterStrokeColor, mCurrentBorderTintColor);

  final float[] positions = new float[6];
  positions[0] = 0f;
  positions[1] = borderRatio;
  positions[2] = 0.5f;
  positions[3] = 0.5f;
  positions[4] = 1f - borderRatio;
  positions[5] = 1f;

  return new LinearGradient(
              0, rect.top,
              0, rect.bottom,
              colors, positions,
              Shader.TileMode.CLAMP);
}
项目:GitHub    文件:CircleProgressBar.java   
public OvalShadow(int shadowRadius, int circleDiameter) {
    super();
    mShadowPaint = new Paint();
    mShadowRadius = shadowRadius;
    mCircleDiameter = circleDiameter;
    mRadialGradient = new RadialGradient(mCircleDiameter / 2, mCircleDiameter / 2,
            mShadowRadius, new int[]{
            FILL_SHADOW_COLOR, Color.TRANSPARENT
    }, null, Shader.TileMode.CLAMP);
    mShadowPaint.setShader(mRadialGradient);
}
项目:LJFramework    文件:ImageUtils.java   
/**
 * 添加倒影
 *
 * @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;
}
项目:ShortcutMenu    文件:CircleDrawable.java   
public CircleDrawable(Bitmap bitmap, int margin) {
    this.margin = margin;
    this.oBitmap = bitmap;
    bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    paint = new Paint();
    paint.setAntiAlias(true);
    paint.setShader(bitmapShader);
}
项目:GitHub    文件:TransformationUtils.java   
/**
 * Creates a bitmap from a source bitmap and rounds the corners.
 *
 * @param inBitmap the source bitmap to use as a basis for the created bitmap.
 * @param width the width of the generated bitmap.
 * @param height the height of the generated bitmap.
 * @param roundingRadius the corner radius to be applied (in device-specific pixels).
 * @return a {@link Bitmap} similar to inBitmap but with rounded corners.
 * @throws IllegalArgumentException if roundingRadius, width or height is 0 or less.
 */
public static Bitmap roundedCorners(@NonNull BitmapPool pool, @NonNull Bitmap inBitmap,
    int width, int height, int roundingRadius) {
  Preconditions.checkArgument(width > 0, "width must be greater than 0.");
  Preconditions.checkArgument(height > 0, "height must be greater than 0.");
  Preconditions.checkArgument(roundingRadius > 0, "roundingRadius must be greater than 0.");

  // Alpha is required for this transformation.
  Bitmap toTransform = getAlphaSafeBitmap(pool, inBitmap);
  Bitmap result = pool.get(width, height, Bitmap.Config.ARGB_8888);

  result.setHasAlpha(true);

  BitmapShader shader = new BitmapShader(toTransform, Shader.TileMode.CLAMP,
      Shader.TileMode.CLAMP);
  Paint paint = new Paint();
  paint.setAntiAlias(true);
  paint.setShader(shader);
  RectF rect = new RectF(0, 0, result.getWidth(), result.getHeight());
  BITMAP_DRAWABLE_LOCK.lock();
  try {
    Canvas canvas = new Canvas(result);
    canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
    canvas.drawRoundRect(rect, roundingRadius, roundingRadius, paint);
    clear(canvas);
  } finally {
    BITMAP_DRAWABLE_LOCK.unlock();
  }

  if (!toTransform.equals(inBitmap)) {
    pool.put(toTransform);
  }

  return result;
}
项目:ShimmerDemo    文件:AbsFocusBorder.java   
private void setShimmerAnimating(boolean shimmerAnimating)
{
    mShimmerAnimating = shimmerAnimating;
    if (mShimmerAnimating)
    {
        mShimmerLinearGradient = new LinearGradient(0, 0, mFrameRectF.width(), mFrameRectF.height(),
            new int[] {0x00FFFFFF, 0x1AFFFFFF, mShimmerColor, 0x1AFFFFFF, 0x00FFFFFF},
            new float[] {0f, 0.2f, 0.5f, 0.8f, 1f}, Shader.TileMode.CLAMP);
        mShimmerPaint.setShader(mShimmerLinearGradient);
    }
}
项目:GitHub    文件:ForecastView.java   
private void initGradient() {
    float centerX = getWidth() * 0.5f;
    Shader gradient = new LinearGradient(
            centerX, 0, centerX, getHeight(),
            currentGradient, null,
            Shader.TileMode.MIRROR);
    gradientPaint.setShader(gradient);
}
项目:GitHub    文件:RoundedBitmapDrawable.java   
private void updatePaint() {
  Bitmap bitmap = getBitmap();
  if (mLastBitmap == null || mLastBitmap.get() != bitmap) {
    mLastBitmap = new WeakReference<Bitmap>(bitmap);
    mPaint.setShader(new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
    mIsShaderTransformDirty = true;
  }
  if (mIsShaderTransformDirty) {
    mPaint.getShader().setLocalMatrix(mTransform);
    mIsShaderTransformDirty = false;
  }
}
项目:JD-Test    文件:MaterialProgressDrawable.java   
public OvalShadow(int shadowRadius, int circleDiameter) {
    super();
    mShadowPaint = new Paint();
    mShadowRadius = shadowRadius;
    mCircleDiameter = circleDiameter;
    mRadialGradient = new RadialGradient(mCircleDiameter / 2, mCircleDiameter / 2,
            mShadowRadius, new int[]{
            FILL_SHADOW_COLOR, Color.TRANSPARENT
    }, null, Shader.TileMode.CLAMP);
    mShadowPaint.setShader(mRadialGradient);
}
项目:LandscapeView    文件:Cloud.java   
public void draw(Canvas canvas) {
    canvas.save(Canvas.MATRIX_SAVE_FLAG);
    canvas.scale(scale, 0.8f * scale, x, y);
    for (Puff p : puffs) {
        LandscapeView.paint.setShader(new RadialGradient(x + p.x, y + p.y - p.size / 2, p.size, new int[]{0xffffffff, p.color}, new float[]{0.9f, 1}, Shader.TileMode.CLAMP));
        LandscapeView.paint.setAlpha(255);
        canvas.drawCircle(x + p.x, y + p.y, p.size, LandscapeView.paint);
    }
    canvas.restore();
}
项目:Rxjava2.0Demo    文件:RoundCircleImageView.java   
public RoundCircleImageView(Bitmap mBitmap) {
    this.mBitmap = mBitmap;
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    BitmapShader shader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    mPaint.setShader(shader);
    mWidth = Math.min(mBitmap.getWidth(), mBitmap.getHeight());
}
项目:Rxjava2.0Demo    文件:RoundImageDrawable.java   
public RoundImageDrawable(Bitmap bitmap) {
    mBitmap = bitmap;
    BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setShader(shader);
    mRectF = new RectF();
}
项目:bubble-rank    文件:BubbleRank.java   
private void setBitmapShaders(int index, Bitmap bitmap) {
    if (bitmap != null && getBigRadius() > 0 && getSmallRadius() > 0) {
        bigPicShaders.put(
                index,
                new BitmapShader(
                        getResizedBitmap(bitmap, getBigRadius() * 2, getBigRadius() * 2),
                        Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
        smallPicShaders.put(
                index,
                new BitmapShader(
                        getResizedBitmap(bitmap, getSmallRadius() * 2, getSmallRadius() * 2),
                        Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
    }
}
项目:KUtils-master    文件:CircleImageView.java   
private void setup() {
    if (!mReady) {
        mSetupPending = true;
        return;
    }

    if (mBitmap == null) {
        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);

    mBitmapHeight = mBitmap.getHeight();
    mBitmapWidth = mBitmap.getWidth();

    mBorderRect.set(0, 0, getWidth(), getHeight());
    mBorderRadius = Math.min((mBorderRect.height() - mBorderWidth) / 2, (mBorderRect.width() - mBorderWidth) / 2);

    mDrawableRect.set(mBorderWidth, mBorderWidth, mBorderRect.width() - mBorderWidth, mBorderRect.height() - mBorderWidth);
    mDrawableRadius = Math.min(mDrawableRect.height() / 2, mDrawableRect.width() / 2);

    updateShaderMatrix();
    invalidate();
}
项目:ucar-weex-core    文件:WXComponent.java   
public void setBackgroundImage(@NonNull String bgImage) {
  if ("".equals(bgImage.trim())) {
    getOrCreateBorder().setImage(null);
  } else {
    Shader shader = WXResourceUtils.getShader(bgImage, mDomObj.getLayoutWidth(), mDomObj.getLayoutHeight());
    getOrCreateBorder().setImage(shader);
  }
}
项目:ucar-weex-core    文件:WXResourceUtils.java   
/**
 * Assembly gradients
 * @param image gradient values contains direction、colors
 * @param width component width
 * @param height component height
 * @return gradient shader
 */
public static Shader getShader(String image, float width, float height) {
  List<String> valueList = parseGradientValues(image);
  if (valueList != null && valueList.size() == 3) {
    float[] points = parseGradientDirection(valueList.get(0), width, height);
    Shader shader = new LinearGradient(points[0], points[1],
                                       points[2], points[3],
                                       getColor(valueList.get(1), Color.WHITE), getColor(valueList.get(2), Color.WHITE),
                                       Shader.TileMode.REPEAT);
    return shader;
  }
  return null;
}
项目:terminal-seekbar    文件:TerminalBackDrawable.java   
@Override
public void draw(Canvas canvas) {

    terminalPaint.setStyle(Paint.Style.FILL);
    terminalPaint.setColor(color);
    terminalPaint.setAlpha(alpha);
    //int[] toAlpha = new int[]{Color.argb(255, Color.red(255), Color.green(255), Color.blue(255)), Color.argb(0, Color.red(0), Color.green(0), Color.blue(0))};
    int[] toAlpha = new int[]{Color.argb(255, 255, 255, 225),Color.argb(0, 0, 0, 0)};
    RadialGradient shader = new RadialGradient(cx, cy,  radius, toAlpha, null, Shader.TileMode.MIRROR);
    terminalPaint.setShader(shader);
    terminalPaint.setStrokeJoin(Paint.Join.ROUND);
    terminalPaint.setStrokeCap(Paint.Cap.ROUND);
    canvas.drawCircle(cx, cy, radius, terminalPaint);
}
项目:RLibrary    文件:SwipeBackLayout.java   
/**
 * 绘制侧滑时, 左边的渐变线
 */
protected void drawSwipeLine(Canvas canvas) {
    if (mTargetView != null && mTargetView.getLeft() != getMeasuredWidth()) {
        mDimRect.set(mTargetView.getLeft() - dimWidth, 0, mTargetView.getLeft(), getMeasuredHeight());
        mPaint.setAlpha((int) (255 * (1 - (mTargetView.getLeft() * 1f / getMeasuredWidth()))));
        mPaint.setShader(new LinearGradient(mDimRect.left, 0, mDimRect.right, 0,
                new int[]{Color.TRANSPARENT, Color.parseColor("#40000000")}, null, Shader.TileMode.CLAMP));
        canvas.drawRect(mDimRect, mPaint);
    }
}