用CGPathRef屏蔽CGContext? [英] Masking CGContext with a CGPathRef?

查看:83
本文介绍了用CGPathRef屏蔽CGContext?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CGContext做一些绘图.我目前正在使用这样的png文件遮罩图形:

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);

这可以正常工作,但是现在我想使用现有的CGPathRef作为我的遮罩. 我应该像上面那样将CGPathRef转换为UIImage和mask吗? 如果是这样,我将如何进行转换? -或者- 有没有更好的方法来解决这个问题?

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?

推荐答案

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

这篇关于用CGPathRef屏蔽CGContext?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆