tags:

views:

727

answers:

2

Hello All,

Do anyone know how I can draw a transparent circle on a CALayer just like using CGContextClearRect to draw a transparent rectangle? My requirements is that I need to draw a mask on a picture, in some cases, I need to erase it, but CGContextClearRect only allow to draw a rectangle, I wonder if there is another way to do the same thing and draw a tranparent circle.

Regards, Anto

A: 

Initially draw the circle and then clip the path and then again clear the bounding rect of the circle by CGContextClearRect.

Shreekara
Could you please provide a piece of sample code? I'm new to Quartz 2d.
CGContextRef context = UIGraphicsGetCurrentContext();CGRect cirleRect = CGRectMake(0,0,100,100);CGContextStrokeEllipseInRect(context,cirleRect);CGContextClip(context);CGContextClearRect(context,cirleRect);This will create a transparant circle with diameter 100 pixels...
Shreekara
+1  A: 

Shreekara's comment is slightly off. Use AddArc instead of StrokeEllipse:

CGRect cirleRect = CGRectMake(0, 0, 100, 100); 
CGContextAddArc(context, 50, 50, 50, 0.0, 2*M_PI, 0);
CGContextClip(context); 
CGContextClearRect(context,cirleRect);
David Kanarek
This works a charm.
half_brick