// create a LinearGradient object Shader shader = new LinearGradient(0, 0, 0, 200, Color.BLUE, Color.RED, Shader.TileMode.CLAMP); // create a Paint object Paint paint = new Paint(); paint.setShader(shader); // draw the rectangle canvas.drawRect(rect, paint);
// load the bitmap image Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.image); // create a BitmapShader object Shader shader = new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); // create a Paint object Paint paint = new Paint(); paint.setShader(shader); // draw the circle canvas.drawCircle(centerX, centerY, radius, paint);Package library: android.graphics.BitmapFactory