iOS多张图片合成一张

用法很简单,如下

#pragma mark - 多张图片合成一张
+ (UIImage *)mergedImages:(NSArray *)imagesArray {
    
    CGFloat maxWidth    = 440;//考虑手机屏幕宽度
    CGFloat totalHeight = 0;
    //计算图片的高度
    for (UIImage *image in imagesArray) {
        totalHeight += image.size.height * maxWidth / image.size.width;
    }
    
    //绘图上下文
    UIGraphicsBeginImageContext(CGSizeMake(maxWidth, totalHeight));
    
    totalHeight = 0;
    for (UIImage *image in imagesArray) {
        
        CGFloat imageWidth  = maxWidth;
        CGFloat imageHeight = image.size.height * maxWidth / image.size.width;
        
        [image drawInRect:CGRectMake(0, totalHeight, imageWidth, imageHeight)];
        totalHeight += imageHeight;
    }
//生成图片 UIImage
*resultingImage = UIGraphicsGetImageFromCurrentImageContext(); //释放上下文 UIGraphicsEndImageContext(); return resultingImage; }
 
原文地址:https://www.cnblogs.com/visonhome/p/4419450.html