Combining Two Images With CIFilter(CISourceOverCompositing)

- (void)generateSampleImage {
CIImage *background = [CIImage imageWithContentsOfURL:
                       [[NSBundle mainBundle] URLForResource:@"background" withExtension:@"png"]];
CIImage *foreground = [CIImage imageWithContentsOfURL:
                       [[NSBundle mainBundle] URLForResource:@"foreground" withExtension:@"png"]];




CIFilter *filter = [CIFilter filterWithName:@"CISourceOverCompositing"];
[filter setValue:background forKey:kCIInputBackgroundImageKey];
[filter setValue:foreground forKey:kCIInputImageKey];
CIImage *outputImage = [filter outputImage];
self.imageView.image = [self imageWithCIImage:outputImage];




NSURL *baseUrl = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory
                                                         inDomains:NSUserDomainMask] objectAtIndex:0];
NSURL *outputUrl = [baseUrl URLByAppendingPathComponent:@"output_image.png"];
[UIImagePNGRepresentation(self.imageView.image) writeToFile:outputUrl.path atomically:YES];
}
Advertisements
Combining Two Images With CIFilter(CISourceOverCompositing)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s