Jun
Jun

Reputation: 3432

How to clip image with another image in CGContext?

I want to get the following result with two images.

Please help me.

Upvotes: 1

Views: 2049

Answers (2)

Paresh Navadiya
Paresh Navadiya

Reputation: 38249

After @Sumanth's code for combine two images you need to mask final image like how-to-mask-an-image link

Upvotes: 3

Sumanth
Sumanth

Reputation: 4921

To combine two images on an image view try this

UIImage *bottomImage = [UIImage imageNamed:@"bottom.png"]; //background image
UIImage *image       = [UIImage imageNamed:@"top.png"]; //foreground image
CGSize newSize = CGSizeMake(width, height);
UIGraphicsBeginImageContext( newSize );
// Use existing opacity as is
[bottomImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
// Apply supplied opacity if applicable
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height) blendMode:kCGBlendModeNormal alpha:0.8];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Add newImage to UIImageView

Upvotes: 3

Related Questions