iOS:逆UIBezierPath(bezierPathWithOvalInRect)
我有一个圆形对象的JPG图像矩形,并希望使圆形对象的透明度…
(在这个例子中删除红色区域)
在这个iOS的帮助下, 使UIImage透明和“UIBezierPath bezierPathWithOvalInRect”的一部分,我已经取得了一些成功,但是这使得我的对象周围的道路,我需要倒过来,使外部而不是内部path透明..
我不知道我必须改变我的代码才能得到正确的结果..
这是我的代码:
//BezierPath UIBezierPath *bezierPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 100, 100)]; // Create an image context containing the original UIImage. UIGraphicsBeginImageContext(_imgTemp.image.size); [_imgTemp.image drawAtPoint:CGPointZero]; // Clip to the bezier path and clear that portion of the image. CGContextRef context = UIGraphicsGetCurrentContext(); CGContextAddPath(context,bezierPath.CGPath); CGContextClip(context); CGContextClearRect(context,CGRectMake(0,0,self._imgTemp.image.size.width,self._imgTemp.image.size.height)); // Build a new UIImage from the image context. UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); self._imgTemp.image = newImage;
有人得到解决?
要只在黑色圆圈内绘制,你应该移动[_imgTemp.image drawAtPoint:CGPointZero];
到CGContextClip(context);
后面CGContextClip(context);
然后完全删除CGContextClearRect( ... )
调用:
//BezierPath UIBezierPath *bezierPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 100, 100)]; // Create an image context containing the original UIImage. UIGraphicsBeginImageContext(_imgTemp.image.size); // Clip to the bezier path and clear that portion of the image. CGContextRef context = UIGraphicsGetCurrentContext(); CGContextAddPath(context,bezierPath.CGPath); CGContextClip(context); // Draw here when the context is clipped [_imgTemp.image drawAtPoint:CGPointZero]; // Build a new UIImage from the image context. UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); self._imgTemp.image = newImage;