Here is the issue i am facing:
I have implemented the masking using maskimage.
Here is the Original Image : (Size: 300width x 418height)
Here is the Mask image: (Size: 165width x 215height)
Below is the code i have used to crop image according to mask & create new UIImage
:
CALayer *mask = [CALayer layer];
mask.contents = (id)[[UIImage imageNamed:@"maskImage.png"] CGImage];
mask.frame = imgMaskImage.frame;
mask.frame = CGRectMake(mask.frame.origin.x-10, mask.frame.origin.y-50, mask.frame.size.width, mask.frame.size.height);
self.imgEditedImageView.layer.mask = mask;
self.imgEditedImageView.layer.masksToBounds = YES;
imgMaskImage.image = nil;
UIGraphicsBeginImageContext(self.imgEditedImageView.frame.size);
[self.imgEditedImageView.layer renderInContext:UIGraphicsGetCurrentContext()];
croppedImage = UIGraphicsGetImageFromCurrentImageContext();
[croppedImage drawInRect:imgMaskImage.frame];
UIGraphicsEndImageContext();
It works & crops image accordingly. Here is the result:
But the issue the Final croppedImage(UIImage) image takes the frame of original image (300x418).
I am not getting why it happens. I have tried so many things but still no solution. Can any one please suggest me if i am doing anything wrong or something is missing.
Thanks.