How to mask/crop a picture using the pattern like the image in UIImageView
? Can any one help me with refrences?
Asked
Active
Viewed 317 times
3

Kanan Vora
- 2,124
- 1
- 16
- 26

Dev_iOS
- 251
- 1
- 2
- 8
1 Answers
5
Pass two images to the below function. 1) Image to be mask and 2) your mask pattern Image.
- (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage {
CGImageRef maskRef = maskImage.CGImage;
CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef),
CGImageGetHeight(maskRef),
CGImageGetBitsPerComponent(maskRef),
CGImageGetBitsPerPixel(maskRef),
CGImageGetBytesPerRow(maskRef),
CGImageGetDataProvider(maskRef), NULL, false);
CGImageRef masked = CGImageCreateWithMask([image CGImage], mask);
return [UIImage imageWithCGImage:masked];
}
You can refer the full tutorial here.
If you want to clip image by passing some path then have a look at this SO Answer.
Hope this will solve your problem.

Community
- 1
- 1

Moin Ahmed
- 2,898
- 21
- 33
-
How can i change the size while masking? – Dev_iOS Jan 28 '13 at 06:06
-
1Check this http://stackoverflow.com/questions/4394491/how-to-compress-resize-image-on-iphone-os-sdk-before-uploading-to-a-server – Paresh Navadiya Jan 28 '13 at 06:09