On Android how do I make oddly shaped clipping areas?

前端 未结 1 1030
青春惊慌失措
青春惊慌失措 2021-02-12 15:57

Here is how to create a clipping area the shape of a circle:

Path path = new Path();
path.addCircle(200,200,100,Direction.CW);
c.clipPath(path); // c is a Canvas         


        
1条回答
  •  情歌与酒
    2021-02-12 16:41

    From the Canvas javadoc:

    Canvas#clipPath(Path path, Region.Op op) - Modify the current clip with the specified path.

    So, for your donut example:

    1. Create 2 Paths. One for the larger circle, one for the smaller circle.
    2. Canvas#clipPath( Path ) with larger circle Path.
    3. Call the Canvas#clipPath( Path, Region.Op ) method on your canvas with the smaller circle Path for the first argument and the appropriate Region.Op enum value for the second argument.

      Path largePath = new Path();
      largePath.addCircle(200,200,100,Direction.CW);
      Path smallPath = new Path();
      smallPath.addCircle(200,200,40,Direction.CW);
      c.clipPath(largePath); // c is a Canvas
      c.clipPath(smallPath, Region.Op.DIFFERENCE);
      

    Again, modify the Region.Op enum value to get different effects...

    0 讨论(0)
提交回复
热议问题