I am working on an application wherein the user draws some closed area on an image. I want to crop any closed area drawn on that image. In a way I would like to achieve this functionality in this app

I have done the drawing part using touches method and CGContext but I am unable to crop the drawn area. Please help me out. i am running out of time for the dead line.

有帮助吗?

解决方案

I guess you have a CGPathRef that you where able to draw in the CGContext. From there you can create a layer, assign the image as a content and use a CAShapeLayer a s a mask to crop it.

CGPathRef path;
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
[shapeLayer setPath:path];

CALayer *imgLayer = [CALayer layer];
[imgLayer setContents:img];
[imgLayer setMask:shapeLayer];

[self.layer addSublayer:imgLayer];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top