how to merge two UIImage and creating single Image

Sometimes we might need to merge or combine two Images and assign it to single UIImage Object ..the following code works exactly for that.

UIImage *firstImage = [UIImage imageNamed:@”a.png”];
UIImage *secondImage = [UIImage imageNamed:@”b.png”];

CGFloat firstWidth = CGGetImageWidth([firstImage CGImage]);
CGFloat firstHeight = CGGetImageHeight([firstImage CGImage]);

CGFloat secondWidth = CGGetImageWidth([secondImage CGImage]);
CGFloat secondHeight = CGGetImageHeight([secondImage CGImage]);

CGSize sizetoNewImage = CGSizeMake(firstWidth+secondWidth , firstHeight); // Here merging two images horizontally ,

UIGraphicsBeginImageContext(sizetoNewImage);

[firstImage drawInRect : CGRectMake(0,0,firstWidth,firstHeight)];
[secondImage drawInRect:CGRectMake(firstWidht,0,secondWidth,secondHeight)];// Here merging two images horizontally ,

UIImage *MergedImage  = UIGraphicsGetImageFromCurrentContext();

UIGraphicsEndImaecontext();

//Thats it

Expecting FeedBack from you

Comments

comments

Leave a Reply

Your email address will not be published. Required fields are marked *