Java 类android.graphics.Shader.TileMode 实例源码

项目:airgram    文件:ColorPicker.java   
private Bitmap createColorWheelBitmap(int width, int height) {

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

        int colorCount = 12;
        int colorAngleStep = 360 / 12;
        int colors[] = new int[colorCount + 1];
        float hsv[] = new float[] { 0f, 1f, 1f };
        for (int i = 0; i < colors.length; i++) {
            hsv[0] = (i * colorAngleStep + 180) % 360;
            colors[i] = Color.HSVToColor(hsv);
        }
        colors[colorCount] = colors[0];

        SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null);
        RadialGradient radialGradient = new RadialGradient(width / 2, height / 2, colorWheelRadius, 0xFFFFFFFF, 0x00FFFFFF, TileMode.CLAMP);
        ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER);

        colorWheelPaint.setShader(composeShader);

        Canvas canvas = new Canvas(bitmap);
        canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint);

        return bitmap;

    }
项目:airgram    文件:MultiColorPicker.java   
private Bitmap createColorWheelBitmap(int width, int height) {

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

        int colorCount = 12;
        int colorAngleStep = 360 / 12;
        int colors[] = new int[colorCount + 1];
        float hsv[] = new float[] { 0f, 1f, 1f };
        for (int i = 0; i < colors.length; i++) {
            hsv[0] = (i * colorAngleStep + 180) % 360;
            colors[i] = Color.HSVToColor(hsv);
        }
        colors[colorCount] = colors[0];

        SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null);
        RadialGradient radialGradient = new RadialGradient(width / 2, height / 2, colorWheelRadius, 0xFFFFFFFF, 0x00FFFFFF, TileMode.CLAMP);
        ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER);

        colorWheelPaint.setShader(composeShader);

        Canvas canvas = new Canvas(bitmap);
        canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint);

        return bitmap;

    }
项目:planetcon    文件:ColorPicker.java   
private Bitmap createColorDiscBitmap(int radius) {
    int centerColor, edgeColor;
    Bitmap bitmap = Bitmap.createBitmap(2 * radius, 2 * radius, Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmap);
    mHSV[0] = 0; mHSV[1] = 1; mHSV[2] = 1;   //red
    SweepGradient sweepGradient = new SweepGradient(radius, radius, getColors(mHSV), null);
    mColorPaint.setShader(sweepGradient);
    canvas.drawCircle(radius, radius, radius, mColorPaint);

    mHSV[0] = 0; mHSV[1] = 0; mHSV[2] = 1;   //white
    centerColor = Color.HSVToColor(255, mHSV);
    edgeColor = Color.HSVToColor(0, mHSV);
    RadialGradient radialGradient = new RadialGradient(radius, radius, radius, centerColor, edgeColor, TileMode.CLAMP);
    mColorPaint.setShader(radialGradient);
    canvas.drawCircle(radius, radius, radius, mColorPaint);

    return bitmap;
}
项目:planetcon    文件:ColorPicker.java   
private void drawColorSquare(Canvas canvas) {
    int pureColor, brightColor, darkColor, transparentColor;

    // pureColor
    mHSV[0] = mColorHSV[0];
    mHSV[1] = 1; mHSV[2] = 1;
    pureColor = Color.HSVToColor(mHSV);
    // brightColor
    mHSV[1] = 0; mHSV[2] = 1;
    brightColor = Color.HSVToColor(mHSV);
    // darkColor
    mHSV[1] = 1; mHSV[2] = 0;
    darkColor = Color.HSVToColor(255, mHSV);
    // alphaColor
    mHSV[1] = 0; mHSV[2] = 0;
    transparentColor = Color.HSVToColor(0, mHSV);

    // drawn without compose shader, but looks worse
    Shader gradient1 = new LinearGradient(mSquareRect.right, mSquareRect.bottom, mSquareRect.right, mSquareRect.top, brightColor, pureColor, TileMode.CLAMP);
    Shader gradient2 = new LinearGradient(mSquareRect.right, mSquareRect.bottom, mSquareRect.left, mSquareRect.bottom, transparentColor, darkColor, TileMode.CLAMP);

    mColorPaint.setShader(gradient1);
    canvas.drawRect(mSquareRect, mColorPaint);
    mColorPaint.setShader(gradient2);
    canvas.drawRect(mSquareRect, mColorPaint);
}
项目:NoticeDog    文件:CircleTransform.java   
public Bitmap transform(Bitmap source) {
    int size = Math.min(source.getWidth(), source.getHeight());
    Bitmap squaredBitmap = Bitmap.createBitmap(source, (source.getWidth() - size) / 2, (source.getHeight() - size) / 2, size, size);
    if (squaredBitmap != source) {
        source.recycle();
    }
    Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    paint.setShader(new BitmapShader(squaredBitmap, TileMode.CLAMP, TileMode.CLAMP));
    paint.setAntiAlias(true);
    float r = ((float) size) / 2.0f;
    canvas.drawCircle(r, r, r, paint);
    squaredBitmap.recycle();
    return bitmap;
}
项目:buildAPKsApps    文件:ColorPicker.java   
private Bitmap createColorWheelBitmap(int width, int height) {

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

        int colorCount = 12;
        int colorAngleStep = 360 / 12;
        int colors[] = new int[colorCount + 1];
        float hsv[] = new float[] { 0f, 1f, 1f };
        for (int i = 0; i < colors.length; i++) {
            hsv[0] = (i * colorAngleStep + 180) % 360;
            colors[i] = Color.HSVToColor(hsv);
        }
        colors[colorCount] = colors[0];

        SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null);
        RadialGradient radialGradient = new RadialGradient(width / 2, height / 2, colorWheelRadius, 0xFFFFFFFF, 0x00FFFFFF, TileMode.CLAMP);
        ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER);

        colorWheelPaint.setShader(composeShader);

        Canvas canvas = new Canvas(bitmap);
        canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint);

        return bitmap;

    }
项目:buildAPKsApps    文件:MultiColorPicker.java   
private Bitmap createColorWheelBitmap(int width, int height) {

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

        int colorCount = 12;
        int colorAngleStep = 360 / 12;
        int colors[] = new int[colorCount + 1];
        float hsv[] = new float[] { 0f, 1f, 1f };
        for (int i = 0; i < colors.length; i++) {
            hsv[0] = (i * colorAngleStep + 180) % 360;
            colors[i] = Color.HSVToColor(hsv);
        }
        colors[colorCount] = colors[0];

        SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null);
        RadialGradient radialGradient = new RadialGradient(width / 2, height / 2, colorWheelRadius, 0xFFFFFFFF, 0x00FFFFFF, TileMode.CLAMP);
        ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER);

        colorWheelPaint.setShader(composeShader);

        Canvas canvas = new Canvas(bitmap);
        canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint);

        return bitmap;

    }
项目:boohee_v5.6    文件:CircleImageView.java   
private void setup() {
    if (!this.mReady) {
        this.mSetupPending = true;
    } else if (this.mBitmap != null) {
        this.mBitmapShader = new BitmapShader(this.mBitmap, TileMode.CLAMP, TileMode.CLAMP);
        this.mBitmapPaint.setAntiAlias(true);
        this.mBitmapPaint.setShader(this.mBitmapShader);
        this.mBorderPaint.setStyle(Style.STROKE);
        this.mBorderPaint.setAntiAlias(true);
        this.mBorderPaint.setColor(this.mBorderColor);
        this.mBorderPaint.setStrokeWidth((float) this.mBorderWidth);
        this.mBitmapHeight = this.mBitmap.getHeight();
        this.mBitmapWidth = this.mBitmap.getWidth();
        this.mBorderRect.set(0.0f, 0.0f, (float) getWidth(), (float) getHeight());
        this.mBorderRadius = Math.min((this.mBorderRect.height() - ((float) this.mBorderWidth)) / 2.0f, (this.mBorderRect.width() - ((float) this.mBorderWidth)) / 2.0f);
        this.mDrawableRect.set((float) this.mBorderWidth, (float) this.mBorderWidth, this.mBorderRect.width() - ((float) this.mBorderWidth), this.mBorderRect.height() - ((float) this.mBorderWidth));
        this.mDrawableRadius = Math.min(this.mDrawableRect.height() / 2.0f, this.mDrawableRect.width() / 2.0f);
        updateShaderMatrix();
        invalidate();
    }
}
项目:boohee_v5.6    文件:CircleBitmapDisplayer.java   
public CircleDrawable(Bitmap bitmap, Integer strokeColor, float strokeWidth) {
    this.radius = (float) (Math.min(bitmap.getWidth(), bitmap.getHeight()) / 2);
    this.bitmapShader = new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP);
    this.mBitmapRect = new RectF(0.0f, 0.0f, (float) bitmap.getWidth(), (float) bitmap
            .getHeight());
    this.paint = new Paint();
    this.paint.setAntiAlias(true);
    this.paint.setShader(this.bitmapShader);
    this.paint.setFilterBitmap(true);
    this.paint.setDither(true);
    if (strokeColor == null) {
        this.strokePaint = null;
    } else {
        this.strokePaint = new Paint();
        this.strokePaint.setStyle(Style.STROKE);
        this.strokePaint.setColor(strokeColor.intValue());
        this.strokePaint.setStrokeWidth(strokeWidth);
        this.strokePaint.setAntiAlias(true);
    }
    this.strokeWidth = strokeWidth;
    this.strokeRadius = this.radius - (strokeWidth / 2.0f);
}
项目:boohee_v5.6    文件:SelectableRoundedImageView.java   
public SelectableRoundedCornerDrawable(Bitmap bitmap, Resources r) {
    this.mBitmap = bitmap;
    this.mBitmapShader = new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP);
    if (bitmap != null) {
        this.mBitmapWidth = bitmap.getScaledWidth(r.getDisplayMetrics());
        this.mBitmapHeight = bitmap.getScaledHeight(r.getDisplayMetrics());
    } else {
        this.mBitmapHeight = -1;
        this.mBitmapWidth = -1;
    }
    this.mBitmapRect.set(0.0f, 0.0f, (float) this.mBitmapWidth, (float) this.mBitmapHeight);
    this.mBitmapPaint = new Paint(1);
    this.mBitmapPaint.setStyle(Style.FILL);
    this.mBitmapPaint.setShader(this.mBitmapShader);
    this.mBorderPaint = new Paint(1);
    this.mBorderPaint.setStyle(Style.STROKE);
    this.mBorderPaint.setColor(this.mBorderColor.getColorForState(getState(), -16777216));
    this.mBorderPaint.setStrokeWidth(this.mBorderWidth);
}
项目:boohee_v5.6    文件:RoundRectDrawableWithShadow.java   
private void buildShadowCorners() {
    RectF innerBounds = new RectF(-this.mCornerRadius, -this.mCornerRadius, this.mCornerRadius, this.mCornerRadius);
    RectF outerBounds = new RectF(innerBounds);
    outerBounds.inset(-this.mShadowSize, -this.mShadowSize);
    if (this.mCornerShadowPath == null) {
        this.mCornerShadowPath = new Path();
    } else {
        this.mCornerShadowPath.reset();
    }
    this.mCornerShadowPath.setFillType(FillType.EVEN_ODD);
    this.mCornerShadowPath.moveTo(-this.mCornerRadius, 0.0f);
    this.mCornerShadowPath.rLineTo(-this.mShadowSize, 0.0f);
    this.mCornerShadowPath.arcTo(outerBounds, 180.0f, 90.0f, false);
    this.mCornerShadowPath.arcTo(innerBounds, 270.0f, -90.0f, false);
    this.mCornerShadowPath.close();
    float startRatio = this.mCornerRadius / (this.mCornerRadius + this.mShadowSize);
    this.mCornerShadowPaint.setShader(new RadialGradient(0.0f, 0.0f, this.mCornerRadius + this.mShadowSize, new int[]{this.mShadowStartColor, this.mShadowStartColor, this.mShadowEndColor}, new float[]{0.0f, startRatio, 1.0f}, TileMode.CLAMP));
    this.mEdgeShadowPaint.setShader(new LinearGradient(0.0f, (-this.mCornerRadius) + this.mShadowSize, 0.0f, (-this.mCornerRadius) - this.mShadowSize, new int[]{this.mShadowStartColor, this.mShadowStartColor, this.mShadowEndColor}, new float[]{0.0f, 0.5f, 1.0f}, TileMode.CLAMP));
    this.mEdgeShadowPaint.setAntiAlias(false);
}
项目:boohee_v5.6    文件:ShadowDrawableWrapper.java   
private void buildShadowCorners() {
    RectF innerBounds = new RectF(-this.mCornerRadius, -this.mCornerRadius, this.mCornerRadius, this.mCornerRadius);
    RectF outerBounds = new RectF(innerBounds);
    outerBounds.inset(-this.mShadowSize, -this.mShadowSize);
    if (this.mCornerShadowPath == null) {
        this.mCornerShadowPath = new Path();
    } else {
        this.mCornerShadowPath.reset();
    }
    this.mCornerShadowPath.setFillType(FillType.EVEN_ODD);
    this.mCornerShadowPath.moveTo(-this.mCornerRadius, 0.0f);
    this.mCornerShadowPath.rLineTo(-this.mShadowSize, 0.0f);
    this.mCornerShadowPath.arcTo(outerBounds, 180.0f, 90.0f, false);
    this.mCornerShadowPath.arcTo(innerBounds, 270.0f, -90.0f, false);
    this.mCornerShadowPath.close();
    float shadowRadius = -outerBounds.top;
    if (shadowRadius > 0.0f) {
        float startRatio = this.mCornerRadius / shadowRadius;
        float midRatio = startRatio + ((1.0f - startRatio) / 2.0f);
        this.mCornerShadowPaint.setShader(new RadialGradient(0.0f, 0.0f, shadowRadius, new int[]{0, this.mShadowStartColor, this.mShadowMiddleColor, this.mShadowEndColor}, new float[]{0.0f, startRatio, midRatio, 1.0f}, TileMode.CLAMP));
    }
    this.mEdgeShadowPaint.setShader(new LinearGradient(0.0f, innerBounds.top, 0.0f, outerBounds.top, new int[]{this.mShadowStartColor, this.mShadowMiddleColor, this.mShadowEndColor}, new float[]{0.0f, SHADOW_HORIZ_SCALE, 1.0f}, TileMode.CLAMP));
    this.mEdgeShadowPaint.setAntiAlias(false);
}
项目:decoy    文件:ZQRoundOvalImageView.java   
/**
 * 设置BitmapShader
 */
private void setBitmapShader() {
    Drawable drawable = getDrawable();
    if (null == drawable) {
        return;
    }
    Bitmap bitmap = drawableToBitmap(drawable);
    // 将bitmap作为着色器来创建一个BitmapShader
    mBitmapShader = new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP);
    float scale = 1.0f;
    if (mType == TYPE_CIRCLE) {
        // 拿到bitmap宽或高的小值
        int bSize = Math.min(bitmap.getWidth(), bitmap.getHeight());
        scale = mWidth * 1.0f / bSize;

    } else if (mType == TYPE_ROUND || mType == TYPE_OVAL) {
        // 如果图片的宽或者高与view的宽高不匹配,计算出需要缩放的比例;缩放后的图片的宽高,一定要大于我们view的宽高;所以我们这里取大值;
        scale = Math.max(getWidth() * 1.0f / bitmap.getWidth(), getHeight() * 1.0f / bitmap.getHeight());
    }
    // shader的变换矩阵,我们这里主要用于放大或者缩小
    mMatrix.setScale(scale, scale);
    // 设置变换矩阵
    mBitmapShader.setLocalMatrix(mMatrix);
    mPaint.setShader(mBitmapShader);

}
项目:controllerformote-android    文件:ColorPicker.java   
private Bitmap createColorWheelBitmap(int width, int height) {

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

        int colorCount = 12;
        int colorAngleStep = 360 / 12;
        int colors[] = new int[colorCount + 1];
        float hsv[] = new float[] { 0f, 1f, 1f };
        for (int i = 0; i < colors.length; i++) {
            hsv[0] = (i * colorAngleStep + 180) % 360;
            colors[i] = Color.HSVToColor(hsv);
        }
        colors[colorCount] = colors[0];

        SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null);
        RadialGradient radialGradient = new RadialGradient(width / 2, height / 2, colorWheelRadius, 0xFFFFFFFF, 0x00FFFFFF, TileMode.CLAMP);
        ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER);

        colorWheelPaint.setShader(composeShader);

        Canvas canvas = new Canvas(bitmap);
        canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint);

        return bitmap;

    }
项目:PerfectShow    文件:ColorPickerCircle.java   
@SuppressLint("DrawAllocation")
@Override
protected void onDraw(Canvas canvas)
{
    super.onDraw(canvas);
    int width  = getMeasuredWidth();
    int height = getMeasuredHeight();

    int new_color = Color.HSVToColor(hsv);
    if(color != new_color)
    {
        Shader shader_x = new LinearGradient(0.0F, 0.0F, width, 0.0F, Color.WHITE, new_color, TileMode.CLAMP);

        ComposeShader shader = new ComposeShader(shader_y, shader_x, PorterDuff.Mode.MULTIPLY);
        paint.setShader(shader);

        color = new_color;
    }
    canvas.drawRect(0.0F, 0.0F, width, height, paint);
}
项目:px-android    文件:ColorPicker.java   
private Bitmap createColorWheelBitmap(int width, int height) {

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

        int colorCount = 12;
        int colorAngleStep = 360 / 12;
        int colors[] = new int[colorCount + 1];
        float hsv[] = new float[]{0f, 1f, 1f};
        for (int i = 0; i < colors.length; i++) {
            hsv[0] = (i * colorAngleStep + 180) % 360;
            colors[i] = Color.HSVToColor(hsv);
        }
        colors[colorCount] = colors[0];

        SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null);
        RadialGradient radialGradient = new RadialGradient(width / 2, height / 2, colorWheelRadius, 0xFFFFFFFF, 0x00FFFFFF, TileMode.CLAMP);
        ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER);

        colorWheelPaint.setShader(composeShader);

        Canvas canvas = new Canvas(bitmap);
        canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint);

        return bitmap;

    }
项目:Upkeep    文件:AmbilWarnaKotak.java   
@Override
protected void onDraw(final Canvas canvas) {
    super.onDraw(canvas);

    if (this.paint == null) {
        this.paint = new Paint();
        this.luar = new LinearGradient(0.f, 0.f, 0.f, this.ukuranUiPx, 0xffffffff, 0xff000000,
                TileMode.CLAMP);
    }

    this.tmp00[1] = this.tmp00[2] = 1.f;
    this.tmp00[0] = this.hue;
    int rgb = Color.HSVToColor(this.tmp00);

    this.dalam = new LinearGradient(0.f, 0.f, this.ukuranUiPx, 0.f, 0xffffffff, rgb,
            TileMode.CLAMP);
    ComposeShader shader = new ComposeShader(this.luar, this.dalam, PorterDuff.Mode.MULTIPLY);

    this.paint.setShader(shader);

    canvas.drawRect(0.f, 0.f, this.ukuranUiPx, this.ukuranUiPx, this.paint);
}
项目:IMKBaseFrameworkLibrary    文件:Reflect3DImage.java   
/**
 * 全倒影
 * 
 * @param originalImage
 * @return
 */
public static Bitmap createReflectedImage(Bitmap originalImage, int imageHeight) {
    int width = originalImage.getWidth();
    int height = originalImage.getHeight();
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, height - imageHeight, width, imageHeight, matrix, false);
    Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + imageHeight), Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmapWithReflection);
    Paint defaultpPaint = new Paint();
    canvas.drawBitmap(originalImage, 0, 0, defaultpPaint);
    canvas.drawBitmap(reflectionImage, 0, height, defaultpPaint);
    Paint paint = new Paint();
    LinearGradient shader = new LinearGradient(0, originalImage.getHeight(), 0, bitmapWithReflection.getHeight(), 0x70ffffff, 0x00ffffff, TileMode.MIRROR);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    canvas.drawRect(0, height, width, bitmapWithReflection.getHeight(), paint);
    reflectionImage.recycle();
    return bitmapWithReflection;
}
项目:BLE_Toolbox_Android    文件:ColorPicker.java   
private Bitmap createColorWheelBitmap(int width, int height) {

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

        int colorCount = 12;
        int colorAngleStep = 360 / 12;
        int colors[] = new int[colorCount + 1];
        float hsv[] = new float[] { 0f, 1f, 1f };
        for (int i = 0; i < colors.length; i++) {
            hsv[0] = (i * colorAngleStep + 180) % 360;
            colors[i] = Color.HSVToColor(hsv);
        }
        colors[colorCount] = colors[0];

        SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null);
        RadialGradient radialGradient = new RadialGradient(width / 2, height / 2, colorWheelRadius, 0xFFFFFFFF, 0x00FFFFFF, TileMode.CLAMP);
        ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER);

        colorWheelPaint.setShader(composeShader);

        Canvas canvas = new Canvas(bitmap);
        canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint);

        return bitmap;

    }
项目:Evisa    文件:CircleView.java   
/**
 * 初始化BitmapShader
 */
private void setUpShader()
{
    Drawable drawable = getDrawable();
    if (drawable == null)
    {
        Log.e("view", "ok");
        return;
    }

    Bitmap bmp = drawableToBitamp(drawable);
    // 将bmp作为着色器,就是在指定区域内绘制bmp
    mBitmapShader = new BitmapShader(bmp, TileMode.CLAMP, TileMode.CLAMP);
    float scale = 1.0f;
    int bSize = Math.min(bmp.getWidth(), bmp.getHeight());
    scale = getWidth() * 1.0f / bSize;
    // shader的变换矩阵,我们这里主要用于放大或者缩小
    matrix.setScale(scale, scale);
    // 设置变换矩阵
    mBitmapShader.setLocalMatrix(matrix);
    // 设置shader
    paint.setShader(mBitmapShader);
}
项目:MyViews    文件:LinearGradientView.java   
public LinearGradientView(Context context) {
    super(context);
    // ��һ�ڶ���������ʾ������㣬���������ڶԽǵ�����λ�ã��������ĸ�������ʾ�����յ㣻�����������ʾ������ɫ��
    // ��������������Ϊ�գ���ʾ����ֵΪ0-1 new float[] {0.25f, 0.5f, 0.75f, 1 }  ���Ϊ�գ���ɫ���ȷֲ������ݶ��ߡ�
    mLinearGradient11 = new LinearGradient(0, 0, 0, 200, new int[] { Color.RED, Color.GREEN, Color.BLUE, Color.BLACK }, null, TileMode.CLAMP);
    mLinearGradient12 = new LinearGradient(0, 0, 0, 300, new int[] { Color.RED, Color.GREEN, Color.BLUE, Color.BLACK }, new float[] { 0, 0.1f, 0.5f, 0.5f }, TileMode.CLAMP);
    mLinearGradient13 = new LinearGradient(0, 0, 0, 400, new int[] { Color.RED, Color.GREEN, Color.BLUE }, null, TileMode.CLAMP);

    mLinearGradient21 = new LinearGradient(0, 320, 0, 320 + 200, new int[] { Color.RED, Color.GREEN, Color.BLUE, Color.BLACK }, null, TileMode.MIRROR);
    mLinearGradient22 = new LinearGradient(0, 320, 0, 320 + 100, new int[] { Color.RED, Color.GREEN, Color.BLUE }, null, TileMode.MIRROR);
    mLinearGradient23 = new LinearGradient(0, 320, 0, 320 + 100, new int[] { Color.RED, Color.GREEN, Color.BLUE }, new float[] { 0, 0.1f, 0.5f }, TileMode.MIRROR);

    mLinearGradient31 = new LinearGradient(0, 640, 0, 640 + 200, new int[] { Color.RED, Color.GREEN, Color.BLUE, Color.BLACK }, null, TileMode.REPEAT);
    mLinearGradient32 = new LinearGradient(0, 640, 0, 640 + 100, new int[] { Color.RED, Color.GREEN, Color.BLUE }, null, TileMode.REPEAT);
    mLinearGradient33 = new LinearGradient(0, 640, 0, 640 + 100, new int[] { Color.RED, Color.GREEN, Color.BLUE }, new float[] { 0, 0.1f, 0.5f }, TileMode.REPEAT);
    mPaint = new Paint();
}
项目:FingerColoring-Android    文件:ColorPicker.java   
private Bitmap createColorWheelBitmap(int width, int height) {

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

        int colorCount = 12;
        int colorAngleStep = 360 / 12;
        int colors[] = new int[colorCount + 1];
        float hsv[] = new float[]{0f, 1f, 1f};
        for (int i = 0; i < colors.length; i++) {
            hsv[0] = (i * colorAngleStep + 180) % 360;
            colors[i] = Color.HSVToColor(hsv);
        }
        colors[colorCount] = colors[0];

        SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null);
        RadialGradient radialGradient = new RadialGradient(width / 2, height / 2, colorWheelRadius, 0xFFFFFFFF, 0x00FFFFFF, TileMode.CLAMP);
        ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER);

        colorWheelPaint.setShader(composeShader);

        Canvas canvas = new Canvas(bitmap);
        canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint);

        return bitmap;

    }
项目:UofT-Timetable    文件:ColorPicker.java   
private Bitmap createColorWheelBitmap(int width, int height) {

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

        int colorCount = 12;
        int colorAngleStep = 360 / 12;
        int colors[] = new int[colorCount + 1];
        float hsv[] = new float[] { 0f, 1f, 1f };
        for (int i = 0; i < colors.length; i++) {
            hsv[0] = (i * colorAngleStep + 180) % 360;
            colors[i] = Color.HSVToColor(hsv);
        }
        colors[colorCount] = colors[0];

        SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null);
        RadialGradient radialGradient = new RadialGradient(width / 2, height / 2, colorWheelRadius, 0xFFFFFFFF, 0x00FFFFFF, TileMode.CLAMP);
        ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER);

        colorWheelPaint.setShader(composeShader);

        Canvas canvas = new Canvas(bitmap);
        canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint);

        return bitmap;

    }
项目:Tower-develop    文件:AttitudeIndicator.java   
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    halfHeight = h / 2f;
    halfWidth = w / 2f;

    radiusExternal = Math.min(halfHeight, halfWidth) / YAW_ARROW_SIZE;
    radiusInternal = radiusExternal * INTERNAL_RADIUS;

    internalBounds = new RectF(-radiusInternal, -radiusInternal, radiusInternal, radiusInternal);

    skyPaint.setShader(new LinearGradient(0, -radiusInternal, 0, radiusInternal, Color
            .parseColor("#0082d6"), Color.parseColor("#2cb1e1"), TileMode.CLAMP));

    groundPaint.setShader(new LinearGradient(0, radiusInternal, 0, radiusInternal, Color
            .parseColor("#4bbba1"), Color.parseColor("#008f63"), TileMode.CLAMP));

}
项目:ToastUI    文件:ColorPickerView.java   
private void drawSatValPanel(Canvas canvas) {
    RectF rect = this.mSatValRect;
    this.mBorderPaint.setColor(this.mBorderColor);
    canvas.drawRect(this.mDrawingRect.left, this.mDrawingRect.top, BORDER_WIDTH_PX + rect.right, BORDER_WIDTH_PX + rect.bottom, this.mBorderPaint);
    if (this.mValShader == null) {
        this.mValShader = new LinearGradient(rect.left, rect.top, rect.left, rect.bottom, -1, ViewCompat.MEASURED_STATE_MASK, TileMode.CLAMP);
    }
    this.mSatShader = new LinearGradient(rect.left, rect.top, rect.right, rect.top, -1, Color.HSVToColor(new float[]{this.mHue, BORDER_WIDTH_PX, BORDER_WIDTH_PX}), TileMode.CLAMP);
    this.mSatValPaint.setShader(new ComposeShader(this.mValShader, this.mSatShader, Mode.MULTIPLY));
    canvas.drawRect(rect, this.mSatValPaint);
    Point p = satValToPoint(this.mSat, this.mVal);
    this.mSatValTrackerPaint.setColor(ViewCompat.MEASURED_STATE_MASK);
    canvas.drawCircle((float) p.x, (float) p.y, this.PALETTE_CIRCLE_TRACKER_RADIUS - (BORDER_WIDTH_PX * this.mDensity), this.mSatValTrackerPaint);
    this.mSatValTrackerPaint.setColor(0xffdddddd);
    canvas.drawCircle((float) p.x, (float) p.y, this.PALETTE_CIRCLE_TRACKER_RADIUS, this.mSatValTrackerPaint);
}
项目:ToastUI    文件:ColorPickerView.java   
private void drawHuePanel(Canvas canvas) {
    RectF rect = this.mHueRect;
    this.mBorderPaint.setColor(this.mBorderColor);
    canvas.drawRect(rect.left - BORDER_WIDTH_PX, rect.top - BORDER_WIDTH_PX, rect.right + BORDER_WIDTH_PX, BORDER_WIDTH_PX + rect.bottom, this.mBorderPaint);
    if (this.mHueShader == null) {
        this.mHueShader = new LinearGradient(rect.left, rect.top, rect.left, rect.bottom, buildHueColorArray(), null, TileMode.CLAMP);
        this.mHuePaint.setShader(this.mHueShader);
    }
    canvas.drawRect(rect, this.mHuePaint);
    float rectHeight = (4.0f * this.mDensity) / 2.0f;
    Point p = hueToPoint(this.mHue);
    RectF r = new RectF();
    r.left = rect.left - this.RECTANGLE_TRACKER_OFFSET;
    r.right = rect.right + this.RECTANGLE_TRACKER_OFFSET;
    r.top = ((float) p.y) - rectHeight;
    r.bottom = ((float) p.y) + rectHeight;
    canvas.drawRoundRect(r, 2.0f, 2.0f, this.mHueTrackerPaint);
}
项目:ToastUI    文件:ColorPickerView.java   
private void drawAlphaPanel(Canvas canvas) {
    if (this.mShowAlphaPanel && this.mAlphaRect != null && this.mAlphaPattern != null) {
        RectF rect = this.mAlphaRect;
        this.mBorderPaint.setColor(this.mBorderColor);
        canvas.drawRect(rect.left - BORDER_WIDTH_PX, rect.top - BORDER_WIDTH_PX, BORDER_WIDTH_PX + rect.right, BORDER_WIDTH_PX + rect.bottom, this.mBorderPaint);
        this.mAlphaPattern.draw(canvas);
        float[] hsv = new float[]{this.mHue, this.mSat, this.mVal};
        this.mAlphaShader = new LinearGradient(rect.left, rect.top, rect.right, rect.top, Color.HSVToColor(hsv), Color.HSVToColor(0, hsv), TileMode.CLAMP);
        this.mAlphaPaint.setShader(this.mAlphaShader);
        canvas.drawRect(rect, this.mAlphaPaint);
        if (!(this.mAlphaSliderText == null || this.mAlphaSliderText == "")) {
            canvas.drawText(this.mAlphaSliderText, rect.centerX(), rect.centerY() + (4.0f * this.mDensity), this.mAlphaTextPaint);
        }
        float rectWidth = (4.0f * this.mDensity) / 2.0f;
        Point p = alphaToPoint(this.mAlpha);
        RectF r = new RectF();
        r.left = ((float) p.x) - rectWidth;
        r.right = ((float) p.x) + rectWidth;
        r.top = rect.top - this.RECTANGLE_TRACKER_OFFSET;
        r.bottom = rect.bottom + this.RECTANGLE_TRACKER_OFFSET;
        canvas.drawRoundRect(r, 2.0f, 2.0f, this.mHueTrackerPaint);
    }
}
项目:j2se_for_android    文件:ImageUtil.java   
public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap){
    final int reflectionGap = 4;
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height/2, width, height/2, matrix, false);
    Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height/2), Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmapWithReflection);
    canvas.drawBitmap(bitmap, 0, 0, null);
    Paint deafalutPaint = new Paint();
    canvas.drawRect(0, height,width,height + reflectionGap, deafalutPaint);
    canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);
    Paint paint = new Paint();
    LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0, bitmapWithReflection.getHeight()
            + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));

    canvas.drawRect(0, height, width, bitmapWithReflection.getHeight()
            + reflectionGap, paint);
    return bitmapWithReflection;
}
项目:material-components-android    文件:CircularRevealHelper.java   
public void buildCircularRevealCache() {
  if (STRATEGY == BITMAP_SHADER) {
    buildingCircularRevealCache = true;
    hasCircularRevealCache = false;

    view.buildDrawingCache();
    Bitmap bitmap = view.getDrawingCache();

    if (bitmap == null && view.getWidth() != 0 && view.getHeight() != 0) {
      bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Config.ARGB_8888);
      Canvas canvas = new Canvas(bitmap);
      view.draw(canvas);
    }

    if (bitmap != null) {
      revealPaint.setShader(new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP));
    }

    buildingCircularRevealCache = false;
    hasCircularRevealCache = true;
  }
}
项目:Codebase    文件:BitmapUtil.java   
/**
 * 获得带倒影的图片方法
 *
 * @param bitmap 源图片
 * @return 带倒影图片
 */
public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap) {
    final int reflectionGap = 4;
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    Bitmap reflectionImage = HSBitmapUtil.createBitmap(bitmap, 0,
            height / 2, width, height / 2, matrix, false);
    Bitmap bitmapWithReflection = HSBitmapUtil.createBitmap(width,
            (height + height / 2), Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmapWithReflection);
    canvas.drawBitmap(bitmap, 0, 0, null);
    Paint deafalutPaint = new Paint();
    canvas.drawRect(0, height, width, height + reflectionGap, deafalutPaint);
    canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);
    Paint paint = new Paint();
    LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0,
            bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff,
            0x00ffffff, TileMode.CLAMP);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    canvas.drawRect(0, height, width, bitmapWithReflection.getHeight()
            + reflectionGap, paint);
    return bitmapWithReflection;
}
项目:Codebase    文件:CircleImageView.java   
/**
 * 初始化BitmapShader
 */
private void setUpShader() {
    Drawable drawable = getDrawable();
    if (drawable == null) {
        return;
    }

    Bitmap bmp = drawableToBitamp(drawable);
    // 将bmp作为着色器,就是在指定区域内绘制bmp
    mBitmapShader = new BitmapShader(bmp, TileMode.CLAMP, TileMode.CLAMP);
    float scale = 1.0f;
    // 拿到bitmap宽或高的小值
    int bSize = Math.min(bmp.getWidth(), bmp.getHeight());
    scale = mWidth * 1.0f / bSize;

    // shader的变换矩阵,我们这里主要用于放大或者缩小
    mMatrix.setScale(scale, scale);
    // 设置变换矩阵
    mBitmapShader.setLocalMatrix(mMatrix);
    // 设置shader
    mBitmapPaint.setShader(mBitmapShader);
}
项目:AyoSunny    文件:ColorPicker.java   
private Bitmap createColorWheelBitmap(int width, int height) {

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

        int colorCount = 12;
        int colorAngleStep = 360 / 12;
        int colors[] = new int[colorCount + 1];
        float hsv[] = new float[] { 0f, 1f, 1f };
        for (int i = 0; i < colors.length; i++) {
            hsv[0] = (i * colorAngleStep + 180) % 360;
            colors[i] = Color.HSVToColor(hsv);
        }
        colors[colorCount] = colors[0];

        SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null);
        RadialGradient radialGradient = new RadialGradient(width / 2, height / 2, colorWheelRadius, 0xFFFFFFFF, 0x00FFFFFF, TileMode.CLAMP);
        ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER);

        colorWheelPaint.setShader(composeShader);

        Canvas canvas = new Canvas(bitmap);
        canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint);

        return bitmap;

    }
项目:info_demo    文件:BitmapUtils.java   
public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap) {
    final int reflectionGap = 4;
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();

    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);

    Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height / 2, width, height / 2, matrix, false);

    Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmapWithReflection);
    canvas.drawBitmap(bitmap, 0, 0, null);
    Paint deafalutPaint = new Paint();
    canvas.drawRect(0, height, width, height + reflectionGap, deafalutPaint);
    canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);
    Paint paint = new Paint();
    LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0, bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP);
    paint.setShader(shader);
    // Set the Transfer mode to be porter duff and destination in
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    // Draw a rectangle using the paint with our linear gradient
    canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint);
    return bitmapWithReflection;
}
项目:TvLauncher    文件:ReflectView.java   
/**
 * Set the bitmap reflection
 *
 * @param bitmap
 * @return
 */
public static Bitmap createReflectedImage(Bitmap bitmap, int reflectHeight) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    if (height <= reflectHeight) {
        return null;
    }
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height
            - reflectHeight, width, reflectHeight, matrix, true);
    Bitmap bitmapWithReflection = Bitmap.createBitmap(width, reflectHeight,
            Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmapWithReflection);
    canvas.drawBitmap(reflectionImage, 0, 0, null);
    LinearGradient shader = new LinearGradient(0, 0, 0,
            bitmapWithReflection.getHeight(), 0x80ffffff, 0x00ffffff,
            TileMode.CLAMP);
    Paint paint = new Paint();
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    canvas.drawRect(0, 0, width, bitmapWithReflection.getHeight(), paint);
    return bitmapWithReflection;
}
项目:droidplanner-master    文件:AttitudeIndicator.java   
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    halfHeight = h / 2f;
    halfWidth = w / 2f;

    radiusExternal = Math.min(halfHeight, halfWidth) / YAW_ARROW_SIZE;
    radiusInternal = radiusExternal * INTERNAL_RADIUS;

    internalBounds = new RectF(-radiusInternal, -radiusInternal, radiusInternal, radiusInternal);

    skyPaint.setShader(new LinearGradient(0, -radiusInternal, 0, radiusInternal, Color
            .parseColor("#0082d6"), Color.parseColor("#2cb1e1"), TileMode.CLAMP));

    groundPaint.setShader(new LinearGradient(0, radiusInternal, 0, radiusInternal, Color
            .parseColor("#4bbba1"), Color.parseColor("#008f63"), TileMode.CLAMP));

}
项目:umeng_community_android    文件:RoundImageView.java   
/**
 * 初始化BitmapShader
 */
private void setUpShader() {
    Drawable drawable = getDrawable();
    Bitmap bmp = drawableToBitamp(drawable);
    if (drawable == null || bmp == null) {
        return;
    }

    // 将bmp作为着色器,就是在指定区域内绘制bmp
    mBitmapShader = new BitmapShader(bmp, TileMode.CLAMP, TileMode.CLAMP);
    float scale = 1.0f;
    // 拿到bitmap宽或高的小值
    int bSize = Math.min(bmp.getWidth(), bmp.getHeight());
    scale = mWidth * 1.0f / bSize;

    // shader的变换矩阵,我们这里主要用于放大或者缩小
    mMatrix.setScale(scale, scale);
    // 设置变换矩阵
    mBitmapShader.setLocalMatrix(mMatrix);
    // 设置shader
    mBitmapPaint.setShader(mBitmapShader);
}
项目:Domo-Android    文件:ColorPicker.java   
private Bitmap createColorWheelBitmap(int width, int height) {

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

        int colorCount = 12;
        int colorAngleStep = 360 / 12;
        int colors[] = new int[colorCount + 1];
        float hsv[] = new float[] { 0f, 1f, 1f };
        for (int i = 0; i < colors.length; i++) {
            hsv[0] = (i * colorAngleStep + 180) % 360;
            colors[i] = Color.HSVToColor(hsv);
        }
        colors[colorCount] = colors[0];

        SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null);
        RadialGradient radialGradient = new RadialGradient(width / 2, height / 2, colorWheelRadius, 0xFFFFFFFF, 0x00FFFFFF, TileMode.CLAMP);
        ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER);

        colorWheelPaint.setShader(composeShader);

        Canvas canvas = new Canvas(bitmap);
        canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint);

        return bitmap;

    }
项目:Domo-Android    文件:MultiColorPicker.java   
private Bitmap createColorWheelBitmap(int width, int height) {

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

        int colorCount = 12;
        int colorAngleStep = 360 / 12;
        int colors[] = new int[colorCount + 1];
        float hsv[] = new float[] { 0f, 1f, 1f };
        for (int i = 0; i < colors.length; i++) {
            hsv[0] = (i * colorAngleStep + 180) % 360;
            colors[i] = Color.HSVToColor(hsv);
        }
        colors[colorCount] = colors[0];

        SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null);
        RadialGradient radialGradient = new RadialGradient(width / 2, height / 2, colorWheelRadius, 0xFFFFFFFF, 0x00FFFFFF, TileMode.CLAMP);
        ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER);

        colorWheelPaint.setShader(composeShader);

        Canvas canvas = new Canvas(bitmap);
        canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint);

        return bitmap;

    }
项目:WeatherStation    文件:GaugeView.java   
/**
 * Set default outer rim paint
 *
 * @return paint
 *          Paint for outer rim
 */
private Paint getDefaultOuterRimPaint() {
    /** Linear gradient to create the 3D effect */
    final LinearGradient verticalGradient = new LinearGradient(mOuterRimRect.left, mOuterRimRect.top, mOuterRimRect.left,
            mOuterRimRect.bottom, Color.rgb(255, 255, 255), Color.rgb(84, 90, 100), TileMode.REPEAT);

    /** Bitmap for outer rim */
    final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.darkwood);
    /** Bitmap shader for the metallic style */
    final BitmapShader outerRimTile = new BitmapShader(bitmap, TileMode.REPEAT, TileMode.REPEAT);
    /** Matrix for outer rim */
    final Matrix matrix = new Matrix();
    matrix.setScale(1.0f / bitmap.getWidth(), 1.0f / bitmap.getHeight());
    outerRimTile.setLocalMatrix(matrix);

    /** Paint for outer rim */
    final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setShader(new ComposeShader(verticalGradient, outerRimTile, PorterDuff.Mode.MULTIPLY));
    paint.setFilterBitmap(true);
    return paint;
}
项目:WeatherStation    文件:GaugeView.java   
/**
 * Set default inner rim paint
 *
 * @return paint
 *          Paint for inner rim
 */
private Paint getDefaultInnerRimPaint() {
    /** Linear gradient to create the 3D effect */
    final LinearGradient verticalGradient = new LinearGradient(mOuterRimRect.left, mOuterRimRect.top, mOuterRimRect.left,
            mOuterRimRect.bottom, Color.rgb(255, 255, 255), Color.rgb(84, 90, 100), TileMode.REPEAT);

    /** Bitmap for inner rim */
    final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.darkerwood);
    /** Bitmap shader for the metallic style */
    final BitmapShader innerRimTile = new BitmapShader(bitmap, TileMode.REPEAT, TileMode.REPEAT);
    /** Matrix for inner rim */
    final Matrix matrix = new Matrix();
    matrix.setScale(1.0f / bitmap.getWidth(), 1.0f / bitmap.getHeight());
    innerRimTile.setLocalMatrix(matrix);

    /** Paint for outer rim */
    final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setShader(new ComposeShader(verticalGradient, innerRimTile, PorterDuff.Mode.MULTIPLY));
    paint.setFilterBitmap(true);
    return paint;
}