Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filling the inverse of the CGPath without clipping

Say I have a CGPath which is a circle in the CGContextRef. What I would like to do is to fill the inverse of the path with color. Demonstrated below where the circle is the current path drawn and I would like to fill the inverse of the circle with color, leaving a hollow hole:

enter image description here

like image 272
Live2Enjoy7 Avatar asked Dec 06 '25 13:12

Live2Enjoy7


1 Answers

First add the rectangle to the path and then add the circle (or whatever your path is) to the same path. Then do an even-odd fill which will won't fill the circle because that is covered by both the circle and the rectangle.

CGMutablePathRef path = CGPathCreateMutable();
CGPathAddRect(path, NULL, bigRect);      // add the big rect
CGPathAddPath(path, NULL, circlePath);   // add your shape (the circle)
CGContextDrawPath(path, kCGPathEOFill);  // even-odd fill
like image 163
David Rönnqvist Avatar answered Dec 08 '25 08:12

David Rönnqvist



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!