码迷,mamicode.com
首页 > 移动开发 > 详细

iOS多张图片合成一张

时间:2015-04-12 14:45:37      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:

用法很简单,如下

#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; }

 

 

iOS多张图片合成一张

标签:

原文地址:http://www.cnblogs.com/visonhome/p/4419450.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!