Frank
Frank

Reputation: 309

Masking CGContext with a CGPathRef?

I am doing some drawing using a CGContext. I am currently masking the drawing using a png file like this:

UIImage * myImage = [UIImage imageNamed:@"frame.png"];
CGContextRef context = UIGraphicsGetCurrentContext ();
CGContextClipToMask(context, self.view.bounds, myImage.CGImage);

This works fine, but now I'd like to use an existing CGPathRef as my mask. Should I look at converting the CGPathRef to a UIImage and mask as above? If so how would I go about doing the conversion? -OR- Is there a better way to approach this?

Upvotes: 8

Views: 5038

Answers (1)

cxa
cxa

Reputation: 4248

CGContextAddPath(context, yourPath);
CGContextClip(context);

Upvotes: 12

Related Questions