Paint setShader - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Paint setShader method.

This code example shows how to use the following methods:setColorFilter, setShader
            canvas.restore();
 
            canvas.save();
            canvas.translate(40.0f + mDrawWidth + 40.0f, 40.0f);
 
            mLargePaint.setShader(mHorGradient);
            canvas.drawText("OpenGL rendering", 0.0f, 20.0f, mLargePaint);
 
            mLargePaint.setShader(mScaled2Shader);
            canvas.drawText("OpenGL rendering", 0.0f, 60.0f, mLargePaint);
 
            mLargePaint.setShader(mCompose2Shader);
            mLargePaint.setColorFilter(mColorFilter);
            canvas.drawText("OpenGL rendering", 0.0f, 100.0f, mLargePaint);
            mLargePaint.setColorFilter(null);
 
            canvas.translate(0.0f, 40.0f + mDrawHeight);
            mLargePaint.setShader(mVertGradient);
            canvas.drawText("OpenGL rendering", 0.0f, 20.0f, mLargePaint);
 

8
CodeRank
This code example shows how to use the following methods:setColor, setPathEffect, setShader, setStyle
This code example shows how to use the following methods:setShader, setXfermode
This code example shows how to use the following methods:setShader, setXfermode
 
	@Override 
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		final int width = getWidth(), height = getHeight();
		final Paint paint = new Paint();
		final LinearGradient shader = new LinearGradient(width / 2, 0, width / 2, height, 0xffffffff, 0x00ffffff,
				Shader.TileMode.CLAMP);
		paint.setShader(shader);
		paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
		canvas.drawRect(0, 0, width, height, paint);
	} 
 
	@Override 
	protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
		final int width = MeasureSpec.getSize(widthMeasureSpec);
		setMeasuredDimension(width, width / 2);
		// super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
	} 
 
8
CodeRank
This code example shows how to use the following methods:setShader
7
CodeRank
This code example shows how to use the following methods:setShader
This code example shows how to use the following methods:getColor, setAntiAlias, setColor, setShader, setStrokeWidth
									2 * r),
							new Ellipse2D(sx + 1 * r, sy + 1 * r, 2 * r,
									2 * r) }));
			break; 
		case 1: 
			this.border = new Paint();
			this.border.setColor(Color.WHITE);
			this.border.setAntiAlias(true);
			this.border.setStyle(Style.STROKE);
			this.border.setStrokeWidth(10);
 
			this.fill = new Paint();
			this.fill.setARGB(165, 0, 0, 0);
 
			this.arcRect = new RectF(0, 0, 0, 0);
			arcRect.top = (height - ARCRADIUS) / 2;
			arcRect.left = (width - ARCRADIUS) / 2;
			arcRect.right = arcRect.left + ARCRADIUS;
			arcRect.bottom = arcRect.top + ARCRADIUS;
 

7
CodeRank
This code example shows how to use the following methods:setShader
 
        SweepGradientView(Context c) {
            super(c);
 
            SweepGradient gradient = new SweepGradient(100.0f, 100.0f, 0xff000000, 0xffffffff);
            mPaint = new Paint();
            mPaint.setShader(gradient);
        } 
 
        @Override 
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            setMeasuredDimension(200, 200); 
        } 
 
        @Override 
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            canvas.drawRect(0.0f, 0.0f, getWidth(), getHeight(), mPaint);
        } 
7
CodeRank
This code example shows how to use the following methods:setAntiAlias, setShader
	public MyRoundCornerDrawable(Bitmap bitmap) {
 
		BitmapShader shader;
		shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP,
				Shader.TileMode.CLAMP);
		paint = new Paint();
		paint.setAntiAlias(true);
		paint.setShader(shader);
	} 
 
	@Override 
	public void draw(Canvas canvas) {
		int height = getBounds().height();
		int width = getBounds().width();
		RectF rect = new RectF(0.0f, 0.0f, width, height);
		canvas.drawRoundRect(rect, 30, 30, paint);
	} 
 
	@Override 
	public void setAlpha(int alpha) {
7
CodeRank
This code example shows how to use the following methods:setShader
        mRect.bottom = getHeight();
        if (mShowingGreen) {
            mColorGradientPaint.setShader(new LinearGradient(
                    0, 0, 0, off-2, RIGHT_COLOR&0xffffff, RIGHT_COLOR, Shader.TileMode.CLAMP));
        } else { 
            mColorGradientPaint.setShader(new LinearGradient(
                    0, 0, 0, off-2, MIDDLE_COLOR&0xffffff, MIDDLE_COLOR, Shader.TileMode.CLAMP));
        } 
        mEdgeGradientPaint.setShader(new LinearGradient(
                0, 0, 0, off/2, 0x00a0a0a0, 0xffa0a0a0, Shader.TileMode.CLAMP));
    } 
 
    @Override 
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        updateIndicator(); 
    } 
 
    @Override 
    protected void onDraw(Canvas canvas) {
7
CodeRank

Related Paint setShader Questions & Answers:

setShader Method Overview
Set or clear the shader object.
See Code Examples for other Android Paint Methods: