Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Merge images to make a single image

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 277
    Comment on it

    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:

    Merge images to make a single image

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: