I found given below code for Merge two image if any one has another code merge this two image into a single image.
When i Merge two uiimageview into a single uiimageview then the Final image getting black or white shade.. Actual Color of masking image not coming in final image
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.navigationController.navigationBarHidden = YES;
imgBack = [UIImage imageNamed:@"img1.jpg"];
imgMask = [UIImage imageNamed:@"img2.png"];
imgBackground.image = imgBack;
imgMasking.image = imgMask;
imgFinally = [self maskImage:imgBack withMask:imgMask];
imgFinal.image = imgFinally;
imgBackground.image= nil;
imgMasking.image = nil;
}
- (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];
}