CoreGraphics FillPath And Stroke Path

后端 未结 2 410
别跟我提以往
别跟我提以往 2021-02-05 06:15

I need to draw an hexagon and fill it with a color build with an Image as pattern. I did:

CGContextSaveGState(context);
CGContextSetLineCap(context, kCGLineCapRo         


        
2条回答
  •  离开以前
    2021-02-05 07:17

    Either use

    CGContextDrawPath(context, kCGPathFillStroke);
    

    as sch suggested, or draw the hexagon again before calling FillPath. StrokePath and FillPath remove the path that you have added to the context, thus the next call will silently fail without a path.

    CGPathRef path = /* drawing hexagon here */;
    CGContextAddPath(context, path);
    CGContextStrokePath(context);
    CGContextAddPath(context, path);
    CGContextFillPath(context);
    

    Note: the two segments of code are not equivalent and gives different result.

提交回复
热议问题