原理:
UIImage *upImg = [UIImage imageNamed:@"mv_01"]; UIImage *downImg = [UIImage imageNamed:@"mv_02"]; CGFloat width = 320.f; CGFloat height = 480.f; UIGraphicsBeginImageContext(CGSizeMake(width, height));//展开画布,自定义尺寸 [upImg drawInRect:CGRectMake(0, 0, width, height/2)]; [downImg drawInRect:CGRectMake(0, height/2, width, height/2)];//根据需要定义子图片的位置 UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();//关闭画布 NSString *path = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]; NSString *filePath = [path stringByAppendingPathComponent:@"result.png"]; [UIImagePNGRepresentation(resultImage) writeToFile:filePath atomically:YES];//保存图片到沙盒 NSLog(@"%@", filePath);