gpt4 book ai didi

iPhone 剪辑图像与路径

转载 作者:行者123 更新时间:2023-12-03 18:42:16 24 4
gpt4 key购买 nike

我想用路径剪辑图像。在《Programming with Quartz》一书中,有一个关于如何绘制由矩形路径裁剪的圆的示例(第 37 页),还有一章关于使用现有图像作为模板的图像 mask (第 10 章)。但我仍然不确定如何使用路径剪辑现有图像。有没有例子或指针?

最佳答案

这是一个应该有效的示例,它将剪切区域设置为路径(在我的例子中,该路径是椭圆形,您可以使用矩形)。然后绘制将被剪切的图像。方法drawRect:在我的例子中是绘制UIView上下文的方法。


- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGMutablePathRef path = CGPathCreateMutable();
//or for e.g. CGPathAddRect(path, NULL, CGRectInset([self bounds], 10, 20));
CGPathAddEllipseInRect(path, NULL, [self bounds]);
CGContextAddPath(context, path);
CGContextClip(context);
CGPathRelease(path);
[[UIImage imageNamed:@"GC.png"] drawInRect:[self bounds]];
}

关于iPhone 剪辑图像与路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2570653/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com