Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge Two Image on to one Image programmatically in iphone

Tags:

Hello I am developing the application which requires to merge two Image , My image size are 320*240 by merging both Image I want the size to be 320 * 480 . How can i do this programitically . Following are the Images

First ImageSecond Image

===================================================================================

enter image description here

like image 413
krish Avatar asked Aug 16 '13 12:08

krish


1 Answers

Just tested this, create your context based on the sizes of the images you are working with and draw them on top of each other (this assumes they are the same width):

UIImage *image1 = [UIImage imageNamed:@"image1.png"];
UIImage *image2 = [UIImage imageNamed:@"image2.png"];

CGSize size = CGSizeMake(image1.size.width, image1.size.height + image2.size.height);

UIGraphicsBeginImageContext(size);

[image1 drawInRect:CGRectMake(0,0,size.width, image1.size.height)];
[image2 drawInRect:CGRectMake(0,image1.size.height,size.width, image2.size.height)];

UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

//Add image to view
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, finalImage.size.width, finalImage.size.height)];
imageView.image = finalImage;
[self.view addSubview:imageView];
like image 139
Chris Tetreault Avatar answered Oct 24 '22 04:10

Chris Tetreault