Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge multiple images into one image in iPhone [closed]

I want to merge multiple images which are of different size & at different points.
I want to merge them all and save it in one copy(image).

so how can i mearge images into one image?

like image 535
Haresh Ghatala Avatar asked Jan 02 '14 07:01

Haresh Ghatala


People also ask

How do you add combine images shortcut iPhone?

Navigate to the Combine Images shortcut web page to automatically open it in the Shortcuts app. Scroll down to the bottom of the page and tap Add Untrusted Shortcut. Tap My Shortcuts in the bottom menu. Tap the newly added Combine Images shortcut followed by OK to run it.

How do I put two pictures together on my iPhone without an app?

Make a Shortcut to Create a Side-by-Side Photo on iPhone Tap the Plus sign to create a shortcut. Search for and then tap Select Photos. Tap on the Select Photos section. Turn on the Select Multiple toggle.


1 Answers

I found the solution which is so simple

you can merge multiple images by creating 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 in follwing way

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");
}
like image 197
Haresh Ghatala Avatar answered Oct 20 '22 01:10

Haresh Ghatala