Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw image into area between two concentric circles in Xcode / objective-c

I have an image (its actually circular) and wish to only draw the part of that image that corresponds to the area between two concentric circles, the outer one is fixed, the inner one can adjust in size.

The outer concentric circle will always correspond to the outside edge of the image - but a "hole" needs to be left in the drawn image - corresponding to the size of the smaller concentric circle.

I'm trying to do this in objective-c for iOS - to draw a variable-sized "viewfinder" control.

Any help much appreciated.

like image 452
Peter London Avatar asked Mar 06 '26 07:03

Peter London


1 Answers

Sounds like the standard case to use CGContextEOClip. Haven't checked this code, but something like:

CGContextRef ctxt = UIGraphicsGetCurrentContext();
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddEllipseInRect(path, NULL, outerCircle);
CGPathAddEllipseInRect(path, NULL, innerCircle);
CGContextEOClip(ctxt);
//Draw your stuff
like image 199
Larry OBrien Avatar answered Mar 07 '26 20:03

Larry OBrien



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!