Is it possible to clip a video to a custom defined CGPath? I realize the UIBezierPath is really just a wrapper but I threw that in for familiarity purposes.
Asked
Active
Viewed 105 times
1 Answers
1
I don't know about videos, but the typical way to clip a view to a path is to create a CAShapeLayer
, set its path
to whatever path you want, then use that CAShapeLayer
as the mask
of the layer
of the view you want to clip.
For example, to make a circular mask of some view you could:
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.bounds.size.width / 2.0, self.view.bounds.size.height / 2.0)
radius:self.view.bounds.size.width * 0.4
startAngle:0
endAngle:2.0 * M_PI
clockwise:YES];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = [path CGPath];
self.myView.layer.mask = shapeLayer;

Rob
- 415,655
- 72
- 787
- 1,044
-
So performance wise, what happens to the pixels that are beyond the clipped area? – daveMac May 28 '13 at 19:44
-
@daveMac I would have guessed that those pixels are calculated and then masked away with some performance degradation (though I'm not sure if it would be observable). It depends entirely upon the internals of the implementation, which we're not privy to. I'd suggest trying out the mask and see if you can see any noticeable performance improvement/degradation. – Rob May 28 '13 at 20:26
-
So this works but the performance for moving them around is really poor. Any other ideas of how this could be achieved? – daveMac Jun 17 '13 at 14:08
-
@daveMac Yeah, that's quite computationally intensive, far beyond what I'd imagine a device could handle. Perhaps dig around looking for third-party video processing APIs, but I wouldn't hold out too much hope. Good luck. – Rob Jun 17 '13 at 14:46