Question

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.

Was it helpful?

Solution

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];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top