tags:

views:

240

answers:

2

I want to clip a rectangle from cgpath with the following code. I don't get any output. What's wrong?

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGMutablePathRef thePath = CGPathCreateMutable();
    CGPathMoveToPoint(thePath,NULL,(self.x1),(self.y1));
    CGPathAddLineToPoint(thePath,NULL,(self.x2),(self.y2));
    CGPathAddLineToPoint(thePath,NULL,bx2,by2);
    CGPathAddLineToPoint(thePath,NULL,bx1,by1);
    CGContextAddPath(context, thePath);
    CGContextClip(context);
    CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
    CFRelease(thePath);
A: 

Do you have a current context? i.e. did you use UIGraphicsBeginImageContext() and UIGraphicsPushContext() before you execute the code shown?

Philippe Leybaert
+2  A: 

I noticed that you set the fill color, but did you actually fill the path? e.g.

CGContextFillPath(context);

Kelvin