I want UIImage masking something like this as shown in the image below but using coregraphics masking, any answer is appreciated
Asked
Active
Viewed 555 times
-2

Jasmine Chaniara
- 61
- 10
1 Answers
2
func maskImage(image:UIImage, mask:(UIImage))-> UIImage {
let imageReference = image.cgImage
let maskReference = mask.cgImage
let imageMask = CGImage(maskWidth: maskReference!.width, height: maskReference!.height, bitsPerComponent: maskReference!.bitsPerComponent, bitsPerPixel: maskReference!.bitsPerPixel, bytesPerRow: maskReference!.bytesPerRow, provider: maskReference!.dataProvider!, decode: nil, shouldInterpolate: true)
let maskedReference = imageReference!.masking(imageMask!)
let maskedImage = UIImage(cgImage:maskedReference!)
return maskedImage
}

Harshal Valanda
- 5,331
- 26
- 63
-
when i am giving source image as square and making image as circle then it is returning circle . where as it has to return the left part of the square which is not occupied by circle – Jasmine Chaniara Feb 20 '17 at 12:04
-
It help me but I need exact reverse of it , can you help me in that ...? – Jasmine Chaniara Feb 21 '17 at 05:59