On Android how do I make oddly shaped clipping areas?

南楼画角 提交于 2019-12-03 10:04:41
jarrad

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...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!