如何创建代表 UIImage 径向部分的 UIImage?

how to create an UIImage that represent a radial portion of an UIImage?

给出下面的图片,百分比为 25%。如何生成另一个代表给定图像径向部分 25% 的 UIImage?非常感谢任何帮助。

输入 输出

- (UIImage *)radialPortion:(float)percent image:(UIImage *)image;
- (UIImage *)radialPortion:(float)percent image:(UIImage *)image
{
    CGSize size = image.size;
    CGRect rect = {CGPointZero,size};
    UIGraphicsBeginImageContext(size);
    CGFloat radius = MAX(size.width, size.height)/2;
    UIBezierPath *path = [UIBezierPath bezierPath];
    CGPoint center = CGPointMake(size.width/2, size.height/2);
    [path moveToPoint:center];
    [path addLineToPoint:CGPointMake(center.x, center.y-radius)];
    [path addArcWithCenter:center radius:radius startAngle:-M_PI_2 endAngle:-M_PI_2+M_PI*2*percent clockwise:1];
    [path closePath];
    [path addClip];
    [image drawInRect:rect];
    return UIGraphicsGetImageFromCurrentImageContext();
}

注意:代码仅适用于示例图像,可能不适用于其他图像。