微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

从NSBezierPath中切出一个矩形

如何解决从NSBezierPath中切出一个矩形

是否可以删除由路径中的“ 1”区域定义的“ 0”块?     

解决方法

绝对。这是裁剪区域的作用:
// Save the current clipping region
[NSGraphicsContext saveGraphicsState];
NSRect dontDrawThisRect = NSMakeRect(x,y,w,h);
// Either:
NSRectClip(dontDrawThisRect);
// Or (usually for more complex shapes):
//[[NSBezierPath bezierPathWithRect:dontDrawThisRect] addClip];
[myBezierPath fill];    // or stroke,or whatever you do
// Restore the clipping region for further drawing
[NSGraphicsContext restoreGraphicsState];
    ,正如评论中指出的那样,卡斯韦尔先生的答案实际上与《任择议定书》要求的相反。此代码示例演示如何从圆(或从任何其他贝塞尔曲线路径中的任何贝塞尔曲线路径)中删除rect。诀窍是“反向”要删除的路径,然后将其附加到原始路径:
NSBezierPath *circlePath = [NSBezierPath bezierPathWithOvalInRect:NSMakeRect(0,100,100)];
NSBezierPath *rectPath = [NSBezierPath bezierPathWithRect:NSMakeRect(25,25,50,50)];
rectPath = [rectPath bezierPathByReversingPath];
[circlePath appendBezierPath:rectPath];
注意:如果贝塞尔曲线路径相互交叉,则情况会变得有些棘手。然后,您必须设置正确的“绕线规则”。     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。