图片合成

头文件:

 

@interface CombineViewController : UIViewController {
	UIImageView *ImageView1;
	UIImageView *ImageView2;
	UIImageView *newImageView;
}

@property (nonatomic, retain) IBOutlet UIImageView *ImageView1;
@property (nonatomic, retain) IBOutlet UIImageView *ImageView2;
@property (nonatomic, retain) IBOutlet UIImageView *newImageView;

- (IBAction) CombineImages:(id)sender;
- (UIImage *)addImage:(UIImage *)image1 toImage:(UIImage *)image2;
@end

 

实现文件:

 

@implementation CombineViewController

@synthesize ImageView1, ImageView2, newImageView;

- (void)viewDidLoad {
	[super viewDidLoad];
	ImageView1.image = [UIImage imageNamed:@"1.jpg"];
	ImageView2.image = [UIImage imageNamed:@"2.jpg"];
}

- (IBAction)CombineImages:(id)sender{
	newImageView.image = [self addImage:ImageView1.image toImage:ImageView2.image];
}

- (UIImage *)addImage:(UIImage *)image1 toImage:(UIImage *)image2{
	UIGraphicsBeginImageContext(image1.size);
	[image1 drawInRect:CGRectMake(0, 0, image1.size.width, image1.size.height)];
	[image2 drawInRect:CGRectMake(0, 0, image2.size.width, image2.size.height)];
	UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
	UIGraphicsEndImageContext();
	return resultImage;
}

- (void)dealloc {
	[ImageView1 release];
	[ImageView2 release];
	[newImageView release];
	[super dealloc];
}

@end

 

示例图:


图片合成

你可能感兴趣的:(ios,iPhone,图片合成)