Created
December 21, 2012 22:03
-
-
Save romyilano/4356176 to your computer and use it in GitHub Desktop.
Merge 2 Images into one image / iOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// source | |
// http://stackoverflow.com/questions/9257992/how-to-combine-merge-2-images-into-1 | |
- (UIImage*)imageByCombiningImage:(UIImage*)firstImage withImage:(UIImage*)secondImage { | |
UIImage *image = nil; | |
CGSize newImageSize = CGSizeMake(MAX(firstImage.size.width, secondImage.size.width), MAX(firstImage.size.height, secondImage.size.height)); | |
if (UIGraphicsBeginImageContextWithOptions != NULL) { | |
UIGraphicsBeginImageContextWithOptions(newImageSize, NO, [[UIScreen mainScreen] scale]); | |
} else { | |
UIGraphicsBeginImageContext(newImageSize); | |
} | |
[firstImage drawAtPoint:CGPointMake(roundf((newImageSize.width-firstImage.size.width)/2), | |
roundf((newImageSize.height-firstImage.size.height)/2))]; | |
[secondImage drawAtPoint:CGPointMake(roundf((newImageSize.width-secondImage.size.width)/2), | |
roundf((newImageSize.height-secondImage.size.height)/2))]; | |
image = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return image; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment