我正在使用UIBezierPath在我的圖像中使用此剪切一個洞。ios - 如何在同一視圖中使用兩條貝塞爾路徑?
UIBezierPath *currentPath = [UIBezierPath bezierPath];
CGPoint tempPoint = CGPointMake(leftEyePos.x+30,leftEyePos.y-25);
[currentPath moveToPoint:CGPointMake(tempPoint.x, tempPoint.y)];
tempPoint = CGPointMake(leftEyePos.x-40,leftEyePos.y-25);
[currentPath addLineToPoint:CGPointMake(tempPoint.x, tempPoint.y)];
tempPoint = CGPointMake(leftEyePos.x-40,leftEyePos.y+10);
[currentPath addLineToPoint:CGPointMake(tempPoint.x, tempPoint.y)];
tempPoint = CGPointMake(leftEyePos.x+30,leftEyePos.y+10);
[currentPath addLineToPoint:CGPointMake(tempPoint.x, tempPoint.y)];
tempPoint = CGPointMake(leftEyePos.x+30, leftEyePos.y-25);
[currentPath addLineToPoint:CGPointMake(tempPoint.x, tempPoint.y)];
這
// Create an image context containing the original UIImage.
UIGraphicsBeginImageContext(filteredImage.size);
[filteredImage drawAtPoint:CGPointZero];
// Clip to the bezier path and clear that portion of the image.
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextAddPath(context,currentPath.CGPath);
CGContextAddPath(context,nextPath.CGPath);
CGContextClip(context);
CGContextClearRect(context,CGRectMake(0,0,filteredImage.size.width,filteredImage.size.height));
// Build a new UIImage from the image context.
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
我想是用另一種路徑。我怎樣才能做到這一點?我想這樣創造新UIBezierPath:UIBezierPath *newPath = [UIBezierPath bezierPath];
我又添加CGPoint:
CGPoint mouthTempPoint = CGPointMake(mouthPos.x-30, mouthPos.y-10);
[newPath addLineToPoint:CGPointMake(mouthTempPoint.x, mouthTempPoint.y)];
mouthTempPoint = CGPointMake(mouthPos.x+30, mouthPos.y-10);
[newPath addLineToPoint:CGPointMake(mouthTempPoint.x, mouthTempPoint.y)];
mouthTempPoint = CGPointMake(mouthPos.x+30, mouthPos.y-30);
[newPath addLineToPoint:CGPointMake(mouthTempPoint.x, mouthTempPoint.y)];
mouthTempPoint = CGPointMake(mouthPos.x-30, mouthPos.y-30);
[newPath addLineToPoint:CGPointMake(mouthTempPoint.x, mouthTempPoint.y)];
mouthTempPoint = CGPointMake(mouthPos.x-30, mouthPos.y-10);
[newPath addLineToPoint:CGPointMake(mouthTempPoint.x, mouthTempPoint.y)];
但是我得到一個錯誤。我的錯誤是<Error>: void CGPathAddLineToPoint(CGMutablePathRef, const CGAffineTransform *, CGFloat, CGFloat): no current point.
有人可以幫助我嗎?
你沒有開始'moveToPoint'在第二個例子嗎? –
我只是複製另一個貝塞爾路徑和cg點。我只是改變變量名稱。我在這裏錯過了什麼? – user3548852