CGContextClipToMask on a CGPath

Hi together,


I need to clip a path. Why this doesnt work?


    CGContextRef context = UIGraphicsGetCurrentContext();
    UIGraphicsBeginImageContext(self.frame.size);
    CGContextRef newContext = UIGraphicsGetCurrentContext();
    [[UIColor redColor] setFill];
    CGContextFillRect(newContext, CGRectMake(0, 0, 100, 100));
    CGImageRef mask = CGBitmapContextCreateImage(UIGraphicsGetCurrentContext());
    UIGraphicsEndImageContext();

    [[UIColor redColor] set];
    CGContextAddRect(context, rect);
    CGContextClipToMask(context, rect, mask);
    CGContextFillPath(context);



Walter

...made it without building an image:

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGRect rect1 = CGRectMake(0, 0, 55, 55);
    CGRect rect2 = CGRectMake(50,50, 100, 100);
    [[UIColor blueColor] set];
   
    CGContextAddRect(context, rect1);
    CGContextClip(context);
    CGContextAddRect(context, rect2);
    CGContextFillPath(context);
CGContextClipToMask on a CGPath
 
 
Q