当前位置: 首页>>代码示例>>Java>>正文


Java Shader类代码示例

本文整理汇总了Java中android.graphics.Shader的典型用法代码示例。如果您正苦于以下问题:Java Shader类的具体用法?Java Shader怎么用?Java Shader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Shader类属于android.graphics包,在下文中一共展示了Shader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setupBitmap

import android.graphics.Shader; //导入依赖的package包/类
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();
}
 
开发者ID:akshay2211,项目名称:Oblique,代码行数:27,代码来源:ObliqueView.java

示例2: resetLinearGradient

import android.graphics.Shader; //导入依赖的package包/类
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);
    }
 
开发者ID:7763sea,项目名称:VirtualHook,代码行数:22,代码来源:ShimmerViewHelper.java

示例3: updateColorDependant

import android.graphics.Shader; //导入依赖的package包/类
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());
    }
}
 
开发者ID:eltos,项目名称:SimpleDialogFragments,代码行数:17,代码来源:ColorWheelView.java

示例4: draw

import android.graphics.Shader; //导入依赖的package包/类
@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);
}
 
开发者ID:google,项目名称:spline,代码行数:25,代码来源:SaturationValueDrawable.java

示例5: BubbleDrawable

import android.graphics.Shader; //导入依赖的package包/类
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);
}
 
开发者ID:leochuan,项目名称:BubbleView,代码行数:25,代码来源:BubbleDrawable.java

示例6: setColor

import android.graphics.Shader; //导入依赖的package包/类
/**
 * 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();
}
 
开发者ID:Datatellit,项目名称:xlight_android_native,代码行数:32,代码来源:SVBar.java

示例7: transform

import android.graphics.Shader; //导入依赖的package包/类
@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;
  }
 
开发者ID:open-android,项目名称:Picasso-transformations,代码行数:17,代码来源:RoundedCornersTransformation.java

示例8: setupView

import android.graphics.Shader; //导入依赖的package包/类
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();
}
 
开发者ID:shenhuanet,项目名称:OpenEyesReading-android,代码行数:20,代码来源:CircleImageView.java

示例9: getSourceMaskBitmap

import android.graphics.Shader; //导入依赖的package包/类
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;
}
 
开发者ID:team-supercharge,项目名称:ShimmerLayout,代码行数:26,代码来源:ShimmerLayout.java

示例10: setColor

import android.graphics.Shader; //导入依赖的package包/类
/**
 * 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();
}
 
开发者ID:mkulesh,项目名称:microMathematics,代码行数:32,代码来源:SVBar.java

示例11: getFotoBitmap

import android.graphics.Shader; //导入依赖的package包/类
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;
    }
 
开发者ID:secompufscar,项目名称:app_secompufscar,代码行数:20,代码来源:Pessoa.java

示例12: setCancelIcon

import android.graphics.Shader; //导入依赖的package包/类
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;
    }
}
 
开发者ID:dewarder,项目名称:HoldingButton,代码行数:19,代码来源:HoldingDrawable.java

示例13: getImageRound

import android.graphics.Shader; //导入依赖的package包/类
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;
    }
 
开发者ID:secompufscar,项目名称:app_secompufscar,代码行数:17,代码来源:Instagram.java

示例14: updateShader

import android.graphics.Shader; //导入依赖的package包/类
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);
}
 
开发者ID:dibakarece,项目名称:DMAudioStreamer,代码行数:19,代码来源:CircleImageView.java

示例15: onDraw

import android.graphics.Shader; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:geeknat,项目名称:spinify_android,代码行数:25,代码来源:TouchImageView.java


注:本文中的android.graphics.Shader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。