1.导入系统库

#import <MobileCoreServices/MobileCoreServices.h>

2.遵守协议

<UIImagePickerControllerDelegate,UINavigationControllerDelegate>

3.创建

#pragma mark 相机--拍照

- (void)openCamera{

UIImagePickerController *ipc = [[UIImagePickerController alloc]init];

ipc.sourceType = UIImagePickerControllerSourceTypeCamera;

ipc.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil];

ipc.allowsEditing = YES;

ipc.delegate = self;

[self presentViewController:ipc animated:YES completion:nil];

}

#pragma mark 录像

- (void)openVideo{

UIImagePickerController *ipc = [[UIImagePickerController alloc]init];

ipc.sourceType = UIImagePickerControllerSourceTypeCamera;

ipc.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, nil];

ipc.videoQuality = UIImagePickerControllerQualityTypeHigh;

ipc.allowsEditing = YES ;

ipc.delegate = self;

[self presentViewController:ipc animated:YES completion:nil];

}

#pragma mark  相册

- (void)openPhoto{

UIImagePickerController *ipc = [[UIImagePickerController alloc]init];

ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

ipc.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil];

ipc.allowsEditing = YES;

ipc.delegate = self;

[self presentViewController: ipc animated:YES completion:nil ];

}

#pragma mark  本地视频

- (void)openVideoList{

UIImagePickerController *ipc = [[UIImagePickerController alloc]init];

ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

ipc.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, nil];

ipc.allowsEditing = YES;

ipc.delegate = self;

[self presentViewController:ipc animated:YES completion:nil];

}

 4.代理方法

#pragma mark --Delegate 拍完后执行

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{

//判断是照片 or 视频

NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];

if ([mediaType isEqualToString:(NSString *)kUTTypeImage] && picker.sourceType == UIImagePickerControllerSourceTypeCamera ) {

//图片

UIImage *theImage = nil;

//判断照片是否允许修改

if ([picker allowsEditing]) {

//获取编辑后的照片

theImage = [info objectForKey:UIImagePickerControllerEditedImage];

}else{

theImage = [info objectForKey:UIImagePickerControllerOriginalImage];

}

//保存至相册

UIImageWriteToSavedPhotosAlbum(theImage, self, nil, nil);

}else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie]){

//视频

//获取视频url

NSURL *mediaUrl = [info objectForKey:UIImagePickerControllerMediaURL];

//保存

//方式一:

//保存视频至相册

NSString *urlPath = [mediaUrl path];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(urlPath)) {

UISaveVideoAtPathToSavedPhotosAlbum(urlPath, self, @selector(video:didFinishSavingWithError:contextInfo:), nil);

}

});

//方式二:

//创建 ALAssetLibrary对象,并保存到媒体看

//        ALAssetsLibrary *assetsLibray = [[ALAssetsLibrary alloc]init];

//        [assetsLibray writeVideoAtPathToSavedPhotosAlbum:mediaUrl completionBlock:^(NSURL *assetURL, NSError *error) {

//            if (!error) {

//                NSLog(@"保存成功");

//            }else{

//                NSLog(@"保存失败%@",error);

//            }

//

//        }];

}

//隐藏

[picker dismissViewControllerAnimated:YES completion:nil];

}

 

#pragma mark --Delegate 功能取消

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{

[picker dismissViewControllerAnimated:YES completion:nil];

}

UIImagePickerController拍照/相册/录像/本地视频的更多相关文章

  1. swift2.0 UIImagePickerController 拍照 相册 录像

    系统 ios9.1 语言swift2.0 在app 里最常用的功能就是多媒体选择,首先我们storyboard 创建一个button 用于触发选择事件 @IBAction func selectIma ...

  2. ios本地相册 照像 本地视频

    -(IBAction)btnClick{ UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate: ...

  3. Swift - 从相册中选择视频(过滤掉照片,使用UIImagePickerController)

    (本文代码已升级至Swift4) 有时我们需要从系统相册中选择视频录像,来进行编辑或者上传操作,这时使用 UIImagePickerController 就可以实现. 默认情况下,UIImagePic ...

  4. 照相、从相册上取照片、播放音频、播放本地视频、播放网络视频、MPMoviePlayerController

    一.照相.从相册上去照片 1. 先判断是否支持照相功能 *判断当前设备是否支持照相功能,支持返回YES 否则返回NO 注意:模拟器不支持照相功能 把握一个原则只要是物理硬件相关的功能模拟器都不支持 例 ...

  5. IOS UIImagePickerController(拍照或者读取相册)

      UIImagePickerController ● 使用UIImagePickerController就可以进行拍照或者读取相册 ● 通过sourceType属性来决定拍照还是读取相册 ➢ UII ...

  6. 案例分享:Qt+Arm基于RV1126平台的内窥镜软硬整套解决方案(实时影像、冻结、拍照、录像、背光调整、硬件光源调整,其他产品也可使用该平台,如视频监控,物联网产品等等)

    自研产品系列方案   1. 基于瑞芯微的 RV1126 芯片平台:  2. 外接 USB 摄像头(OV9734. OV6946.OV2740 等 UVC 模块)作为图像输入源:  3. 可通过 LED ...

  7. Android 开发 Camera类的拍照与录像

    前言 在开发Android应用的时候,如果需要调用摄像头拍照或者录像,除了通过Intent调用系统现有相机应用进行拍照录像之外,还可以通过直接调用Camera硬件去去获取摄像头进行拍照录像的操作.本篇 ...

  8. 真正可用的安卓webview html图片上传限制突破处理(拍照+相册都可以用)

    两篇起步使用webview参考文章,第一篇解除限制,但会调用外部浏览器打开链接,第二篇 覆盖shouldOverrideUrlLoading return true https://www.jb51. ...

  9. 项目实战:Qt+Ffmpeg+OpenCV相机程序(打开摄像头、支持多种摄像头、分辨率调整、翻转、旋转、亮度调整、拍照、录像、回放图片、回放录像)

    若该文为原创文章,未经允许不得转载原博主博客地址:https://blog.csdn.net/qq21497936原博主博客导航:https://blog.csdn.net/qq21497936/ar ...

随机推荐

  1. Number,parseInt,parseFloat函数

    Number,parseInt,parseFloat函数 console.group('Number'); console.log(Number( console.log(Number( consol ...

  2. HTTP的GET方法模拟

    进行GET方法的测试 #telnet[ ]10.1.1.11[ ]80 GET[ ]/[ ]HTTP/1.0 [两个回车] HEAD[]/[]HTTP/1.0[回车回车] http://www.cnb ...

  3. PHP那些最好的轮子

    PHP那些最好的轮子 Databse 数据库ORM Doctrine 2 License : MIT Source Code Allo点评:Doctrine是功能最全最完善的PHP ORM,社区一直很 ...

  4. SpringMVC 前端获得定义JSON对象的方法

    SpringMVC 前端获得定义JSON对象的方法: 可以使用map进行对象的创建,这样就会解析成键值对,不需要为前端专门定义对象.

  5. 2017-01-27-hibernate环境搭建

    Hibernate的环境搭建(uid方式): 1:导入包 2:创建实体对象 3:hibernate的映射配置文件 4:hibernate的核心配置文件 5:创建测试类实现表的创建 2:创建实体对象-U ...

  6. Brainfuck与Ook!编程语言解析与解密

    MarkdownPad Document html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,ab ...

  7. 一次开放接口从需求分析到发布sdk线上包

    新年开场篇,欢迎来点赞:本篇和大家分享的是使用webapi做得接口服务验证框架,需求来源是我打算把上篇提到的图片验证码做成一种服务提供给大家,尽管我在上篇已经把代码打包开源了,但是如果有一种快速对接成 ...

  8. UE4中的集合:TSet容器

    好久没有更新了,最近一直在老家过年,网络不通的,今天才有时间更新一集. 一.TSet<T>是什么 UE4中,除了TArray动态数组外,还提供了各种各样的模板容器.这一节,我们就介绍集合容 ...

  9. 【Java】Objects 源码学习

    2017-02-10 by 安静的下雪天  http://www.cnblogs.com/quiet-snowy-day/p/6387321.html    本篇概要 Objects 与 Object ...

  10. [译] AR SDK的种类比你想得要多!这里介绍七个棒棒哒

    作者:Eddie Offermann 原文:There are dozens more Augmented Reality SDKs than you think! Here are seven gr ...