在iOS中,我试图绘制一个剪辑图像。我想剪裁是从一个边缘弯曲到最远的相对边缘。下图以红色显示最终图像的边框。在这个例子中,曲线从左下到右上。从边缘的UIBezier路径曲线
这是我目前写的代码。我唯一的问题是这种方法bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:
不曲线到我需要的扩展。
- (UIImage *)roundCorneredImage:(UIImage *)image radius:(CGFloat)radius {
CGRect imageRect = CGRectZero;
imageRect.size = image.size;
UIGraphicsBeginImageContextWithOptions(imageRect.size, NO, [UIScreen mainScreen].scale);
CGSize size = CGSizeMake(radius, radius);
[[UIBezierPath bezierPathWithRoundedRect:imageRect byRoundingCorners:UIRectCornerBottomRight cornerRadii:size] addClip];
[image drawInRect:imageRect];
UIImage* result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return result;
}
UPDATE:
继承人我得到的结果和我更新的代码。我需要一些进一步的帮助......
UIBezierPath* bezier = [UIBezierPath bezierPath];
[bezier moveToPoint:CGPointMake(0, 0)];
[bezier addLineToPoint:CGPointMake(0, imageRect.size.height)];
[bezier addArcWithCenter:CGPointMake(imageRect.size.width/2, imageRect.size.height/2)
radius:imageRect.size.height/2
startAngle:M_PI/2
endAngle:0
clockwise:NO];
[bezier addLineToPoint:CGPointMake(0, 0)];
[bezier addClip];
我是新来的这个iOS领域,并没有完全理解所有的参数是什么。你可以用示例代码更新你的答案,这样我就可以开始工作,然后我可以从那里调整它。谢谢 – cnotethegr8
@ cnotethegr8这可能是一个很好的机会来看看[文档](https://developer.apple.com/library/ios/documentation/uikit/reference/UIBezierPath_class/Reference/Reference.html#//apple_ref/ occ/instm/UIBezierPath/addArcWithCenter:radius:startAngle:endAngle:顺时针:) –
@DavidRönnqvist该文档不会帮助我。它是我现在需要的细节。我不知道如何完成曲线。我会用我更新的代码更新我的问题。 – cnotethegr8