0

我试图让我的图像在底部的角落透明,以支持面部弯曲的外观。我尝试过使用以下代码,但CGPathAddArc有点令人困惑,因为我不是一个数学虚张声势。如图所示的红色角定义了我想要透明的区域

我有的

我想要透明的红线形状

UIGraphicsBeginImageContext(originalImage.size);
[originalImage drawAtPoint:CGPointZero];

CGMutablePathRef testRef = CGPathCreateMutable();
//CGAffineTransform temp = CGAffineTransformMakeRotation(M_PI / 2);
//CGPathAddEllipseInRect(testRef, &temp, CGRectMake(0,0,20,20));
//CGPathAddQuadCurveToPoint(testRef, nil, 20,20, 150, 150);
//CGPathAddCurveToPoint(testRef, NULL, 20, 20, 40, 40, 100, 100);

CGPathMoveToPoint(testRef, NULL, 20, 20);
CGPathAddArc(testRef, NULL, 0, 15, 15, M_PI_2, -M_PI_2, true);

// Clip to the path and clear that portion of the image.
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextAddPath(context,testRef);
CGContextClip(context);
CGContextClearRect(context,CGRectMake(0,0,originalImage.size.width,originalImage.size.height));
    // Build a new UIImage from the image context.
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
4

1 回答 1

0

如果你对核心基础和低级的东西不太熟悉,你可以简单地使用[UIBezierPath bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:]得到一个圆角的矩形。

例子:

    UIGraphicsBeginImageContext(originalImage.size);
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, originalImage.size.width, originalImage.size.height)
                                               byRoundingCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight
                                                     cornerRadii:CGSizeMake(15, 15)];
    [path addClip];
    [originalImage drawAtPoint:CGPointZero];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
于 2013-06-21T08:02:24.490 回答