Reputation: 73
I have used CAShapeLayer for masking my image and i want to retrieve only the portion that i have masked. When i retrieve, i am getting only the full image.
Can anyone please provide me some code/information regarding this ?
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = CGRectMake(0, 0, clippingPath.bounds.size.width, clippingPath.bounds.size.height) ;
maskLayer.path = [clippingPath CGPath];
maskLayer.fillColor = [[UIColor blackColor] CGColor];
maskLayer.backgroundColor = [[UIColor clearColor] CGColor];
[ imgView removeFromSuperview ] ;
imgView.layer.mask = maskLayer ;
Thanks in advance :)
Upvotes: 0
Views: 256
Reputation: 12081
A CALayer
is for display only, it is not actually modifying the image itself.
To mask an image you'll have to create that yourself, either using Quartz 2D drawing or using CIFilter
/CIImage
from the CoreImage framework.
To mask an image using Core Graphics (Quartz 2D) use CGImageCreateWithMask
and CGImageMaskCreate
. These functions allow you to mask one image with the contents of the other. You say you now use a bezier path to mask, so you would have to render that path into an image first to be able to mask your original image.
To mask an image using CoreImage take a look at the CIBlendWithMask
filter.
Upvotes: 1