Code example for BitmapShader

Methods: setLocalMatrix

0
	private void createShader( int w, int h ) {
		int bitmapWidth = (int) ( w * SHADER_MULTIPLIER );
		 
		// now draw the lines on the new bitmap 
		Bitmap linesBitmap = Bitmap.createBitmap( bitmapWidth, mLinesSingle.getIntrinsicHeight(), Config.ARGB_8888 );
		Shader shader = new BitmapShader( ( (BitmapDrawable) mLinesSingle ).getBitmap(), TileMode.REPEAT, TileMode.CLAMP );
		Canvas canvas = new Canvas( linesBitmap );
		Paint paint = new Paint( Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG | Paint.FILTER_BITMAP_FLAG );
		paint.setShader( shader );
 
		final int w2 = linesBitmap.getWidth() / 2;
		final int indicator_width = mLinesIndicator.getIntrinsicWidth();
		int left = w2 - indicator_width / 2;
		int right = w2 + indicator_width / 2;
 
		double rest = left % mLineWidth;
 
		// left side 
		Matrix matrix = new Matrix();
		matrix.setTranslate( (float) +rest, 0 );
		shader.setLocalMatrix( matrix );
		canvas.drawRect( 0, 0, left, linesBitmap.getHeight(), paint );
 
		// indicator 
		mLinesIndicator.setBounds( left, 0, right, linesBitmap.getHeight() );
		mLinesIndicator.draw( canvas );
 
		// right side 
		shader.setLocalMatrix( null );
		canvas.drawRect( right, 0, linesBitmap.getWidth(), linesBitmap.getHeight(), paint );
 
		mShader = new BitmapShader( linesBitmap, TileMode.CLAMP, TileMode.CLAMP );
		mLinesPaint.setShader( mShader );
		mShaderMatrix = new Matrix();