Monday 9 June 2014

Combine one UIImage onto of another UIImage : 

Check the Full Sample From Here : Sample Code

Combining two images, especially useful, if the overlay image has an alpha value:

 
#import <Foundation/Foundation.h> 
 
@interface UIImage (combine)
- (UIImage*)overlayWith:(UIImage*)overlayImage;
@end
 
 
And the implementation file.

#import "UIImage+Category.h" 
 
@implementation UIImage (combine)
 
- (UIImage*)overlayWith:(UIImage*)overlayImage {
   UIGraphicsBeginImageContext(self.size);
   [self drawAtPoint:CGPointZero];
   [overlayImage drawAtPoint:CGPointZero];
   UIImage *combinedImage = UIGraphicsGetImageFromCurrentImageContext();
   UIGraphicsEndImageContext();
   return combinedImage;
}
 
@end
 

Above i have declare the UIImage+Category Lib files for the UIImage.

You can see the below sample Example for calling the method for combining
the one image to another and set both images to one images.

You can combine multiple images using this methods.:
#import "ViewController.h"
#import "UIImage+Overlay.h"

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.theImageView.image = [self mergingImage];
}

-(UIImage *)mergingImage {
    UIImage *background = [UIImage imageNamed:@"background.png"];
    UIImage *audiImage = [UIImage imageNamed:@"audi.png"];
    UIImage *combineImage = [background overlayWith:audiImage];
    return combineImage;
}
 
You can Download Transparent images from Here : images.zip 
Output of the Project : 







audi.png
 
 
 
Background.png

 
 


       +
 
 
 
 
 
Combine image
 

No comments:

Post a Comment