I found a solution that is so simple
you can combine multiple images by creating the following method
- (BOOL) mergedImageOnMainImage:(UIImage *)mainImg WithImageArray:(NSArray *)imgArray AndImagePointArray:(NSArray *)imgPointArray { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; UIGraphicsBeginImageContext(mainImg.size); [mainImg drawInRect:CGRectMake(0, 0, mainImg.size.width, mainImg.size.height)]; int i = 0; for (UIImage *img in imgArray) { [img drawInRect:CGRectMake([[imgPointArray objectAtIndex:i] floatValue], [[imgPointArray objectAtIndex:i+1] floatValue], img.size.width, img.size.height)]; i+=2; } CGImageRef NewMergeImg = CGImageCreateWithImageInRect(UIGraphicsGetImageFromCurrentImageContext().CGImage, CGRectMake(0, 0, mainImg.size.width, mainImg.size.height)); UIGraphicsEndImageContext(); [pool release]; if (NewMergeImg == nil) { return NO; } else { UIImageWriteToSavedPhotosAlbum([UIImage imageWithCGImage:NewMergeImg], self, nil, nil); return YES; } }
now call this method as follows
NSArray *imgArray = [[NSArray alloc] initWithObjects: [UIImage imageNamed:@"image06.png"], [UIImage imageNamed:@"image07.png"], [UIImage imageNamed:@"image08.png"], [UIImage imageNamed:@"image09.png"], [UIImage imageNamed:@"BackBtn.png"], [UIImage imageNamed:@"Facebook.png"], nil]; NSArray *imgPointArray = [[NSArray alloc] initWithObjects: @"10", @"10", @"10", @"25", @"30", @"15", @"30", @"50", @"20", @"80", @"25", @"100", nil]; BOOL suc = [self mergedImageOnMainImage:[UIImage imageNamed:@"img001.png"] WithImageArray:imgArray AndImagePointArray:imgPointArray]; if (suc == YES) { NSLog(@"Images Successfully Mearged & Saved to Album"); } else { NSLog(@"Images not Mearged & not Saved to Album"); }
Haresh ghatala
source share