draw path with hole ( android )

后端 未结 2 582
星月不相逢
星月不相逢 2021-01-11 13:58

Does anyone have a hint for me for the following problem ?

I would like to draw a filled path ( canvas ) which has a hole in it. In SVG the path definition is the f

相关标签:
2条回答
  • 2021-01-11 14:52

    You should use Path.setFillType(Path.FillType.EVEN_ODD):

    final Path path = new Path();
    final Paint paint = new Paint();
    
    paint.setColor(Color.RED);
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL_AND_STROKE);
    
    path.moveTo(100, 100);
    path.lineTo(200, 100);
    path.lineTo(200, 200);
    path.lineTo(100, 200);
    path.close();
    
    path.moveTo(150, 150);
    path.lineTo(180, 150);
    path.lineTo(180, 180);
    path.lineTo(150, 180);
    path.close();
    
    path.setFillType(Path.FillType.EVEN_ODD);
    canvas.drawPath(path, paint);
    
    0 讨论(0)
  • 2021-01-11 14:53

    SVG determines what's inside/outside a path by using the fill-rule. Java also allows a winding rule to be set. With Android paths there is also a fillType which works similarly. Perhaps you have different rules set for the java or SVG code?

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