Android Shader - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Shader class.

This code example shows how to use the following methods:setLocalMatrix
            mPaint.setShader(mSweepGradient);
            canvas.drawRect(0.0f, 0.0f, 200.0f, 200.0f, mPaint);
 
            canvas.translate(-800.0f, 300.0f);
 
            mRadialGradient.setLocalMatrix(null);
            mPaint.setShader(mRadialGradient);
            canvas.drawRect(0.0f, 0.0f, 200.0f, 200.0f, mPaint);
             
            canvas.translate(400.0f, 000.0f);
             
            mRadialGradient.setLocalMatrix(mMatrix);
            mPaint.setShader(mRadialGradient);
            canvas.drawRect(0.0f, 0.0f, 200.0f, 200.0f, mPaint);
 
            canvas.translate(400.0f, 000.0f);
             
            mRadialGradient.setLocalMatrix(mMatrix2);
            mPaint.setShader(mRadialGradient);
            canvas.drawRect(0.0f, 0.0f, 200.0f, 200.0f, mPaint);

7
CodeRank
This code example shows how to use the following methods:setLocalMatrix
            mPaint.setShader(mSweepGradient);
            canvas.drawRect(0.0f, 0.0f, 200.0f, 200.0f, mPaint);
 
            canvas.translate(-800.0f, 300.0f);
 
            mRadialGradient.setLocalMatrix(null);
            mPaint.setShader(mRadialGradient);
            canvas.drawRect(0.0f, 0.0f, 200.0f, 200.0f, mPaint);
             
            canvas.translate(400.0f, 000.0f);
             
            mRadialGradient.setLocalMatrix(mMatrix);
            mPaint.setShader(mRadialGradient);
            canvas.drawRect(0.0f, 0.0f, 200.0f, 200.0f, mPaint);
 
            canvas.translate(400.0f, 000.0f);
             
            mRadialGradient.setLocalMatrix(mMatrix2);
            mPaint.setShader(mRadialGradient);
            canvas.drawRect(0.0f, 0.0f, 200.0f, 200.0f, mPaint);

7
CodeRank
This code example shows how to use the following methods:setLocalMatrix
This code example shows how to use the following methods:setLocalMatrix
            mBG = new BitmapShader(bm,
                                   Shader.TileMode.REPEAT,
                                   Shader.TileMode.REPEAT);
            Matrix m = new Matrix();
            m.setScale(6, 6);
            mBG.setLocalMatrix(m);
        } 
 
        @Override protected void onDraw(Canvas canvas) {
            canvas.drawColor(Color.WHITE);
 
            Paint labelP = new Paint(Paint.ANTI_ALIAS_FLAG);
            labelP.setTextAlign(Paint.Align.CENTER);
 
            Paint paint = new Paint();
            paint.setFilterBitmap(false);
 
            canvas.translate(15, 35);
 
            int x = 0;
6
CodeRank
This code example shows how to use the following methods:setLocalMatrix
    static BitmapShader newBitmapShader(Bitmap thumb, Matrix destMatrix) {
        float scaleX = (float) THUMB_WIDTH / thumb.getWidth();
        float scaleY = (float) THUMB_HEIGHT / thumb.getHeight();
        destMatrix.setScale(scaleX, scaleY);
 
        BitmapShader shader = new BitmapShader(thumb, TileMode.CLAMP, TileMode.CLAMP);
        shader.setLocalMatrix(destMatrix);
        return shader;
    } 
 
    static void setBounds(Rect bounds, int offsetLeft, int offsetTop) {
        bounds.set(0, 0, THUMB_WIDTH, THUMB_HEIGHT);
        bounds.offsetTo(offsetLeft, offsetTop);
    } 
 
    static void draw(Canvas c, BitmapShader thumbShader, int alpha) {
        // Fade out the outline while fading in the thumbnail. 
        int outlineAlpha = thumbShader != null ? 255 - alpha : 255;
        if (outlineAlpha > 0) {
            THUMB_OUTLINE_PAINT.setAlpha(outlineAlpha);
6
CodeRank
This code example shows how to use the following methods:setLocalMatrix
	@Override 
	protected void onBoundsChange( Rect bounds ) {
		super.onBoundsChange( bounds );
		if ( null != mBitmap ) {
			mMatrix.setScale( 1, (float) bounds.height() / mBitmap.getHeight() );
			mShader.setLocalMatrix( mMatrix );
		} 
	} 
 
	/* 
	 * (non-Javadoc) 
	 *  
	 * @see android.graphics.drawable.Drawable#getOpacity() 
	 */ 
	@Override 
	public int getOpacity() { 
		return PixelFormat.TRANSLUCENT;
	} 
 
	/* 
6
CodeRank
This code example shows how to use the following methods:setLocalMatrix
            mBG = new BitmapShader(bm,
                                   Shader.TileMode.REPEAT,
                                   Shader.TileMode.REPEAT);
            Matrix m = new Matrix();
            m.setScale(6, 6);
            mBG.setLocalMatrix(m);
        } 
 
        @Override protected void onDraw(Canvas canvas) {
            canvas.drawColor(Color.WHITE);
 
            Paint labelP = new Paint(Paint.ANTI_ALIAS_FLAG);
            labelP.setTextAlign(Paint.Align.CENTER);
 
            Paint paint = new Paint();
            paint.setFilterBitmap(false);
 
            canvas.translate(15, 35);
 
            int x = 0;
6
CodeRank
This code example shows how to use the following methods:setLocalMatrix
                || USE_DARK_FADE_IN_HW_ACCELERATED_MODE) {
            Paint p = new Paint();
            Matrix matrix = new Matrix();
            // use use a height of 1, and then wack the matrix each time we 
            // actually use it. 
            Shader fade = new LinearGradient(0, 0, 0, 1, 0xCC000000, 0, Shader.TileMode.CLAMP);
            // PULL OUT THIS CONSTANT 
 
            p.setShader(fade);
 
            // draw the fade effect 
            boolean drawTop = false;
            boolean drawBottom = false;
            boolean drawLeft = false;
            boolean drawRight = false;
 
            float topFadeStrength = 0.0f;
            float bottomFadeStrength = 0.0f;
            float leftFadeStrength = 0.0f;
            float rightFadeStrength = 0.0f;

5
CodeRank
This code example shows how to use the following methods:setLocalMatrix
        canvas.drawRect(0, childh, childw, selfh, mDarkPaint);
 
        /* Carve out the reflection area's alpha channel. */ 
        mMatrix.setScale(1, poolh);
        mMatrix.postTranslate(0, childh);
        mShader.setLocalMatrix(mMatrix);
        canvas.drawRect(0, childh, childw, selfh, mReflectionPaint);
 
        /* Apply the canvas layer. */ 
        canvas.restore();
    } 
} 
5
CodeRank
This code example shows how to use the following methods:postScale, setTranslate, setLocalMatrix
			if (drawable == null) {
				init(); 
				return true; 
			} 
 
			matrix.setTranslate(3 * RADIUS - x, 3 * RADIUS - y);
			matrix.postScale(2.0f, 2.0f);
			drawable.getPaint().getShader().setLocalMatrix(matrix);
			// bounds,就是那个圆的外切矩形 
 
			// if (x < 4 * RADIUS) { 
			// drawable.setBounds(x, y - RADIUS * 4, x + RADIUS * 4, y); 
			// } 
			// else if (y < 4 * RADIUS) { 
			// drawable.setBounds(x - RADIUS * 4, y, x, y + RADIUS * 4); 
			// } else { 
			drawable.setBounds(x - RADIUS * 4, y - RADIUS * 4, x, y);
			// } 
			invalidate();
			break; 
5
CodeRank

Related Android Shader Questions & Answers:

See Code Examples for Android Shader Methods: