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. Linux文件权限与目录配置

    一.linux文件属性 用户组概念:假如主机有两个团体,第一个团体名为projecta,里面有class1,class2,class3:第二个团体名为projecb,里面有class4,class5, ...

  2. XMLSocket的bug

    "<cross-domain-policy>" "<site-control permitted-cross-domain-policies=\&quo ...

  3. spring mvc 与 jasper Report集成

    http://blog.csdn.net/jia20003/article/details/8471169 注意其中的图片地址说明: 如果有子报表,也会到class文件夹中去寻找: 如果子报表有路径的 ...

  4. 001.MVC基本概述

    MVC的基本概念 一.NET平台下开发web应用程序的方案(方法) 方案A:ASP.NET webForm1.web窗体:臃肿(胖)性能低 优点:有很多的web控件可以使用,能够方便的和服务端交互(数 ...

  5. json-lib之复杂数据类型的转换

    在json字符串转java bean时,一般的对象,可以直接转,如:一个学生类,属性有姓名.年龄等 public class Student{ private String sname; privat ...

  6. python中文编码问题深入分析(一):字符编码基础

    背景:笔者作为一名刚接触python语言的新手,在实际的项目中,遇到过一些中文编码问题,初次遇到这些问题的时候,刚开始显得有些手足无措,也不知从何查起.常言道:有问题,找度娘!当我打开www.baid ...

  7. 基于vue2+vuex2+vue-router+axios+elementUI做的自动化后台模板

    github地址:https://github.com/sailengsi/sls-admin 此项目重点突出在架构上模式,这个架构模式,可以让我们在开发中,很方便的拓展与维护,并且可以保持结构清晰的 ...

  8. php 引入文件 include 和require

    php 如何引用文件? 先建一个php 文件,php文件名要和所建的类名相同, 然后直接在php 中用include("")/include"" 和requir ...

  9. Trick 小记

    1.\[P(A|BC) = \frac{P(AB|C)}{P(B|C)}\] 2. In EM algorithm, the usual expectation function can be wri ...

  10. 【WC2015】混淆与破解 (Goldreich-Levin 算法)

    这个嘛= =直接贴VFK的题解就行了吧,感觉自己还是差别人太多 http://vfleaking.blog.uoj.ac/blog/104 讲得挺明白了的说,但还是挺难理解的说,中间实现部分简直不要太 ...