Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create one UIImage from two UIImageView

I have two UIImageView on the UIView. Each UIImageView have one UIImage. Now i want create an one UIImage from two UIImageView.

Please give the suggestion how can i do this.

like image 239
Amit Battan Avatar asked Jan 05 '10 10:01

Amit Battan


1 Answers

If your have a view with three UIImageViews and create corresponding outlets

IBOutlet UIImageView *imageView1;
IBOutlet UIImageView *imageView2;
IBOutlet UIImageView *imageView3;

You can do something like the following to combine imageViews 1 and 2 into imageView 3

UIGraphicsBeginImageContext(imageView1.image.size);  

CGRect rect = CGRectMake(0, 0, imageView1.image.size.width, imageView1.image.size.height);

[imageView1.image drawInRect:rect];  
[imageView2.image drawInRect:rect blendMode:kCGBlendModeScreen alpha:0.5];  

UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();  
UIGraphicsEndImageContext();  

[imageView3 setImage:resultingImage];

CGBlendMode allows you to choose from any of the following compositing operations for your images:

enum CGBlendMode {
   kCGBlendModeNormal,
   kCGBlendModeMultiply,
   kCGBlendModeScreen,
   kCGBlendModeOverlay,
   kCGBlendModeDarken,
   kCGBlendModeLighten,
   kCGBlendModeColorDodge,
   kCGBlendModeColorBurn,
   kCGBlendModeSoftLight,
   kCGBlendModeHardLight,
   kCGBlendModeDifference,
   kCGBlendModeExclusion,
   kCGBlendModeHue,
   kCGBlendModeSaturation,
   kCGBlendModeColor,
   kCGBlendModeLuminosity,
   kCGBlendModeClear,
   kCGBlendModeCopy,
   kCGBlendModeSourceIn,
   kCGBlendModeSourceOut,
   kCGBlendModeSourceAtop,
   kCGBlendModeDestinationOver,
   kCGBlendModeDestinationIn,
   kCGBlendModeDestinationOut,
   kCGBlendModeDestinationAtop,
   kCGBlendModeXOR,
   kCGBlendModePlusDarker,
   kCGBlendModePlusLighter
};
like image 158
Niels Castle Avatar answered Oct 31 '22 15:10

Niels Castle