Android BitmapShader - 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 BitmapShader class.

This code example shows how to use the following methods:setLocalMatrix
This code example shows how to use the following methods:
 
    private void initializeBitmapShader() { 
	// A bitmap-shader to draw the bitmap. 
        // Clamp mode will repeat the last row of pixels. 
        // Hence its better to have an endAlpha of 0 for the linear-gradient. 
	BitmapShader bitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
 
	// A linear-gradient to specify the opacity of the bitmap. 
	LinearGradient gradient = new LinearGradient(0, 0, 0, mBitmap.getHeight(), mStartColor, mEndColor, Shader.TileMode.CLAMP);
 
	// Make a combined shader -- a performance win. 
        // The linear-gradient is the 'SRC' and the bitmap-shader is the 'DST'. 
	// Drawing the DST in the SRC will provide the opacity. 
	mPaint.setShader(new ComposeShader(bitmapShader, gradient, PorterDuff.Mode.DST_IN));
    } 
} 
6
CodeRank
This code example shows how to use the following methods:
            Bitmap bm = Bitmap.createBitmap(new int[] { 0xFFFFFFFF, 0xFFCCCCCC,
                                            0xFFCCCCCC, 0xFFFFFFFF }, 2, 2, 
                                            Bitmap.Config.RGB_565);
            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);
 
6
CodeRank
This code example shows how to use the following methods:
	private Paint paint;
 
	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);
	} 
 
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:
 
	private void init( Bitmap bitmap ) {
		mBitmap = bitmap;
 
		if ( mBitmap != null ) {
			mShader = new BitmapShader( mBitmap, TileMode.REPEAT, TileMode.CLAMP );
			mPaint.setShader( mShader );
		} 
	} 
 
	/* 
	 * (non-Javadoc) 
	 *  
	 * @see android.graphics.drawable.Drawable#draw(android.graphics.Canvas) 
	 */ 
	@Override 
	public void draw( Canvas canvas ) {
		if ( null != mBitmap ) {
			copyBounds( mRect );
			canvas.drawPaint( mPaint );
6
CodeRank
This code example shows how to use the following methods:
            Bitmap bm = Bitmap.createBitmap(new int[] { 0xFFFFFFFF, 0xFFCCCCCC,
                                            0xFFCCCCCC, 0xFFFFFFFF }, 2, 2, 
                                            Bitmap.Config.RGB_565);
            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);
 
6
CodeRank
This code example shows how to use the following methods:
		int w = right - left;
 
		if ( w > 0 && changed || mForceLayout ) {
			mRealRect = new Rect( mPaddingLeft, top, w - mPaddingRight, bottom );
			mIndicatorSmall = makeBitmap2( w / mSmallTicksCount, bottom - top, mLineTickSize );
			mShader = new BitmapShader( mIndicatorSmall, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP );
			mIndicatorBig = makeBitmap3( mRealRect.width() / mBigTicksCount, bottom - top, mLineBigSize );
			mShader1 = new BitmapShader( mIndicatorBig, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP );
			mIndicator = makeIndicator( bottom - top, mLineBigSize );
			mCorrectionX = ( ( (float) mRealRect.width() / mBigTicksCount ) % 1 ) * mBigTicksCount;
			mForceLayout = false;
		} 
	} 
 
	@Override 
	protected void onDraw( Canvas canvas ) {
		super.onDraw( canvas );
 
		if ( mShader != null ) {
			canvas.setDrawFilter( mFast );
6
CodeRank
This code example shows how to use the following methods:
		int w = right - left;
 
		if ( w > 0 && changed || mForceLayout ) {
			mRealRect = new Rect( mPaddingLeft, top, w - mPaddingRight, bottom );
			mIndicatorSmall = makeBitmap2( w / mSmallTicksCount, bottom - top, mLineTickSize );
			mShader = new BitmapShader( mIndicatorSmall, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP );
			mIndicatorBig = makeBitmap3( mRealRect.width() / mBigTicksCount, bottom - top, mLineBigSize );
			mShader1 = new BitmapShader( mIndicatorBig, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP );
			mIndicator = makeIndicator( bottom - top, mLineBigSize );
			mCorrectionX = (((float)mRealRect.width() / mBigTicksCount) % 1)*mBigTicksCount;
			mForceLayout = false;
		} 
	} 
 
	@Override 
	protected void onDraw( Canvas canvas ) {
		super.onDraw( canvas );
		 
 
		if ( mShader != null ) {
5
CodeRank
This code example shows how to use the following methods:
 
  @Override 
  public Pattern createPattern(Image img) { 
    Asserts.checkArgument(img instanceof AndroidImage); 
    Bitmap bitmap = ((AndroidImage) img).getBitmap(); 
    BitmapShader shader = new BitmapShader(bitmap, TileMode.REPEAT, TileMode.REPEAT); 
    return new AndroidPattern(shader); 
  } 
 
  @Override 
  public Gradient createRadialGradient(float x, float y, float r, int[] colors, float[] positions) { 
    RadialGradient gradient = new RadialGradient(x, y, r, colors, positions, TileMode.CLAMP); 
    return new AndroidGradient(gradient); 
  } 
 
  @Override 
  public int screenHeight() { 
    return displayMetrics.heightPixels; 
  } 
 
5
CodeRank

Related Android BitmapShader Questions & Answers:

See Code Examples for Android BitmapShader Methods: