Search code examples
androidmask

Draw text with a shape mask?


I am drawing text on a canvas. I would like to draw a solid circle of color over the text, and only have the circle be painted where it intersects the text. Example:

enter image description here

and what I want to do:

enter image description here

I'm not sure if this is possible, my draw code is simply:

public void onDraw(Canvas canvas) {
    canvas.drawText("Hello", x, y, paint);
    paint.setColor(orange);
    canvas.drawOval(...);
}

I suppose I would need to apply some masking, but not sure how to get started.


Solution

  • follow this tutorial from a googler... android-shaders-filters

    BitmapShader may help you