相关疑难解决方法(0)

34
推荐指数
3
解决办法
4万
查看次数

使用UIImage填充UIBezierPath

我有一个圆形的UIBezierpath:

UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:100];
Run Code Online (Sandbox Code Playgroud)

但后来我想用UIImage填充圆圈(仅显示圆圈内的图像的一部分)

最诚挚的问候克里斯蒂安

编辑:

感谢Daniel和Dave的出色答案:D给我带来了很多麻烦; D

解决方案:

CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextAddPath(ctx, path.CGPath);
CGContextClip(ctx);
Run Code Online (Sandbox Code Playgroud)

和:

path.addClip;
Run Code Online (Sandbox Code Playgroud)

两者都很完美,但我最终使用了最后一种方法(由戴夫),因为它需要更少的代码.

cocoa objective-c

6
推荐指数
1
解决办法
4976
查看次数

iOS:反向UIBezierPath(bezierPathWithOvalInRect)

我有一个jpg图像与矩形中的圆形对象,并希望使圆形对象的envoirement透明...

例

(在此示例中删除红色区域)

在这个iOS的帮助下,UIImage透明和"UIBezierPath bezierPathWithOvalInRect"的一部分我已经取得了一些成功,但这会围绕我的对象形成一条路径,我需要将其反转,以使外部而不是内部路径透明..

我不知道在哪里我必须更改我的代码以获得正确的结果..

这是我的代码:

//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;
Run Code Online (Sandbox Code Playgroud)

有人解决了吗?

transparency image core-graphics ios uibezierpath

0
推荐指数
1
解决办法
4474
查看次数