【代码笔记】iOS-多张图片合成一张

摘要:
RootViewController.m#import“RootViewControler.h”@interfaceRootViewController()@end@implementationRootViewController-(id)initWithNibName:(NSString*)nibNameOrNilbundle:

代码:

 

RootViewController.m

 

复制代码
#import "RootViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    NSArray *imgArray = [[NSArray alloc] initWithObjects:
                         [UIImage imageNamed:@"1.jpg"],
                         [UIImage imageNamed:@"2.jpg"],
                         [UIImage imageNamed:@"3.jpg"],
                         [UIImage imageNamed:@"4.jpg"],
                         [UIImage imageNamed:@"5.jpg"],
                        nil];
    
    NSArray *imgPointArray = [[NSArray alloc] initWithObjects:
                              @"10", @"10",
                              @"10", @"25",
                              @"30", @"15",
                              @"30", @"50",
                              @"20", @"80",
                              nil];
    
    
    BOOL suc = [self mergedImageOnMainImage:[UIImage imageNamed:@"1.jpg"] WithImageArray:imgArray AndImagePointArray:imgPointArray];
    
    if (suc == YES) { 
        NSLog(@"Images Successfully Mearged & Saved to Album"); 
    } 
    else { 
        NSLog(@"Images not Mearged & not Saved to Album"); 
    }
    
}
#pragma -mark -functions
//多张图片合成一张
- (BOOL) mergedImageOnMainImage:(UIImage *)mainImg WithImageArray:(NSArray *)imgArray AndImagePointArray:(NSArray *)imgPointArray
{
    
    UIGraphicsBeginImageContext(mainImg.size);
    
    [mainImg drawInRect:CGRectMake(0, 0, mainImg.size.width, mainImg.size.height)];
    int i = 0;
    for (UIImage *img in imgArray) {
        [img drawInRect:CGRectMake([[imgPointArray objectAtIndex:i] floatValue],
                                   [[imgPointArray objectAtIndex:i+1] floatValue],
                                   img.size.width,
                                   img.size.height)];
        
        i+=2;
    }
    
    CGImageRef NewMergeImg = CGImageCreateWithImageInRect(UIGraphicsGetImageFromCurrentImageContext().CGImage,
                                                          CGRectMake(0, 0, mainImg.size.width, mainImg.size.height));
    
    UIGraphicsEndImageContext();
    if (NewMergeImg == nil) {
        return NO;
    }
    else {
        UIImageWriteToSavedPhotosAlbum([UIImage imageWithCGImage:NewMergeImg], self, nil, nil);
        return YES;
    }
}



- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
复制代码

 

免责声明:文章转载自《【代码笔记】iOS-多张图片合成一张》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇利用MsChart控件绘制多曲线图表es6中find方法下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

js获取高度和宽度

  CreateTime--2017年7月24日10:15:47Author:Marydon js获取高度和宽度 参考连接:http://www.cnblogs.com/EasonJim/p/6229517.html 实现方式:     style.height----offsetHeight,style.width----offsetWidth 第一种...

Elasticsearch集群运维

一、索引管理 1、 创建索引 PUT test-2019-03 {          "settings": {                    "index": {                             "number_of_shards": 10,                             "number_of_r...

Linux大文件分割split和合并cat使用方法

本文主要介绍linux下两个命令:split和cat。其中,相信大家都熟悉cat命令,一般用来查看一个文件的内容,但是它还其它的功能,比如这里要介绍的文件合并功能,它可把多个文件内容合并到一个文件中。从split词义不拿理解,其为分割之意,常用于分割大文件。下面详细介绍。 split命令 — 分割文件 语法:split [–help][–version][...

【Mybatis-Plus】使用updateById()、update()将字段更新为null或者空

问题背景: 最近测试同学给我提了个bug,字段不能置空,我查看了下项目配置发现是字段级别被设置为NOT_EMPTY导致的。 mybatis-plus FieldStrategy 有三种策略: 1.IGNORED:0 忽略 2.NOT_NULL:1 非 NULL,默认策略 3.NOT_EMPTY:2 非空 而默认更新策略是NOT_NULL:非 NULL;即通...

在vue 项目中嵌入jsp页面

今日一个项目中一块功能模块是其他系统使用jsp已经开发好的页面,想着直接将其嵌入到当前的vue项目中节约开发成本;但是发现并非想象的那么简单 创建一个server.vue组件加载jsp页面 1 、第一种(使用 v-html进行jsp 渲染) server.vue <template> <div class="docker-serve...

springmvc 后端入口参数接收

package controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.R...