How to combine multiple UIImageView into one UIImage

I have 2 UIImageViews lying on top of each other (picture + overlay frame), and I want to save them in the camera roll as 1 image.

How can I combine these 2 UIImageViews so that I can call the UIImageWriteToSavedPhotosAlbum function using the "result" of UIImage?

+3
source share
3 answers

I don’t have my Mac at the moment, but I have done this before. The process is what you convert UIImageViewto a raster context, then create CGImagefrom that context that you can use to create a new one UIImage. Read on CGBitmapContext, includingCGBitmapContextCreateImage

+4
+ (UIImage * ) mergeImage: (UIImage *) imageA
                                 withImage:  (UIImage *) imageB
                                 strength: (float) strength {

UIGraphicsBeginImageContextWithOptions(CGSizeMake(imageA.size.width, imageA.size.height), YES, 0.0); 

[imageA drawAtPoint: CGPointMake(0,0)];

[imageB drawAtPoint: CGPointMake(0,0) 
          blendMode: kCGBlendModeNormal // you can play with this
              alpha: strength]; // 0 - 1

UIImage *answer = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext();
return answer; }
+14

, :

- (UIImage * ) mergeImage: (UIImage *) imageA withImage:  (UIImage *) imageB
{

UIGraphicsBeginImageContextWithOptions(CGSizeMake(imageA.size.width, imageA.size.height), YES, 0.0);

[imageA drawAtPoint: CGPointMake(0,0)];

[imageB drawAtPoint: CGPointMake(0,0)
          blendMode: kCGBlendModeNormal // you can play with this
              alpha: 1]; // 0 - 1

UIImage *answer = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return answer;

}
+1

Source: https://habr.com/ru/post/1739454/


All Articles