【问题标题】:Masking CGContext with a CGPathRef?用 CGPathRef 屏蔽 CGContext?
【发布时间】:2012-02-29 16:18:02
【问题描述】:

我正在使用 CGContext 进行一些绘图。我目前正在使用这样的 png 文件屏蔽绘图:

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

这很好用,但现在我想使用现有的 CGPathRef 作为我的掩码。 我应该看一下将 CGPathRef 转换为 UIImage 和上面的掩码吗? 如果是这样,我将如何进行转换? -或者- 有没有更好的方法来解决这个问题?

【问题讨论】:

    标签: objective-c core-graphics cgpath


    【解决方案1】:
    CGContextAddPath(context, yourPath);
    CGContextClip(context);
    

    【讨论】:

    • 这适用于矩形和椭圆。但如果路径是由 addArcWithCenter:radius:... 创建的,则不适用于我,而当我只需要保留一条像素线时。
    • 不想被剪裁怎么办?例如,如果我们想屏蔽图像上的自定义路径而不将其剪切到路径的边界? @cxa
    猜你喜欢
    • 1970-01-01
    • 2017-10-19
    • 2015-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-26
    • 2011-10-11
    相关资源
    最近更新 更多