Mask UIImage iOS by Marcio Valenzuela
Mask UIImage iOS by Marcio Valenzuela

– (void)viewDidLoad
[super viewDidLoad];
UIImage *imageToMask = [UIImage imageNamed:@”koko.jpg”];
UIImageView *imageToMaskImgView = [[UIImageView alloc] initWithImage:imageToMask];
CGRect imgRect = CGRectMake(0, 0, imageToMaskImgView.frame.size.width, imageToMaskImgView.frame.size.height);
UIView *maskMaster = [[UIView alloc] initWithFrame:imgRect];
[maskMaster setBackgroundColor:[UIColor whiteColor]];
[maskMaster addSubview:imageToMaskImgView];
[maskMaster.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
NSLog(@”%@ is the view image”, viewImage);
UIImage *bFooImg = [UIImage imageNamed:@”blackapple.png”];
self.myPic.image = [self maskImage:bFooImg withMask:viewImage];
– (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage {
CGImageRef maskRef = maskImage.CGImage;
CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef),
CGImageGetDataProvider(maskRef), NULL, false);
CGImageRef masked = CGImageCreateWithMask([image CGImage], mask);
return [UIImage imageWithCGImage:masked];

One Comment

  • I was just looking at your How to mask a UIImage in iOS – Santiapps site and see that your website has the potential to become very popular. I just want to tell you, In case you don’t already know… There is a website network which already has more than 16 million users, and most of the users are looking for topics like yours. By getting your website on this network you have a chance to get your site more popular than you can imagine. It is free to sign up and you can read more about it here: – Now, let me ask you… Do you need your website to be successful to maintain your business? Do you need targeted visitors who are interested in the services and products you offer? Are looking for exposure, to increase sales, and to quickly develop awareness for your site? If your answer is YES, you can achieve these things only if you get your website on the service I am describing. This traffic network advertises you to thousands, while also giving you a chance to test the service before paying anything at all. All the popular websites are using this service to boost their traffic and ad revenue! Why aren’t you? And what is better than traffic? It’s recurring traffic! That’s how running a successful site works… Here’s to your success! Find out more here:

Leave a Reply