It is easy to merge different images to make a single image. It is like pasting images to a canvas and taking picture of that canvas. Below I have explained how to do it.
-(UIImage*)combineImages:(NSMutableArray *)images{
CGRect frame = self.view.frame;
CGRect imageViewFrame = CGRectMake(0, 0, frame.size.width/2, frame.size.width/2);
UIImage *firstImage = [images objectAtIndex:0];
UIImage *secImage = [images objectAtIndex:1];
UIImage *imageThree = [images objectAtIndex:2];
UIImage *imageFour = [images objectAtIndex:3];
CGSize finalSize = CGSizeMake(frame.size.width, imageViewFrame.size.height*2);
UIGraphicsBeginImageContextWithOptions(finalSize, YES, 0.0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [[UIColor lightGrayColor] CGColor]);
CGContextFillRect(context, CGRectMake(0, 0, finalSize.width, finalSize.height));
[firstImage drawInRect:CGRectMake(0, 0, imageViewFrame.size.width, imageViewFrame.size.height)];
[secImage drawInRect:CGRectMake(imageViewFrame.size.width, 0, imageViewFrame.size.width, imageViewFrame.size.height)];
[imageThree drawInRect:CGRectMake(0, imageViewFrame.size.height, imageViewFrame.size.width, imageViewFrame.size.height)];
[imageFour drawInRect:CGRectMake(imageViewFrame.size.width, imageViewFrame.size.height, imageViewFrame.size.width, imageViewFrame.size.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
Final result will look like this:
0 Comment(s)