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. 关于oracle导出时的query用法

    QUERY参数后面跟的是where条件,值得注意的是,整个where子句需要使用""括起来,where子句的写法和SELECT中相同: 如果是UNIX平台所有"和'都需 ...

  2. Java策略模式(Strategy模式) 之体验

    <JAVA与模式>之策略模式 在阎宏博士的<JAVA与模式>一书中开头是这样描述策略(Strategy)模式的: 策略模式属于对象的行为模式.其用意是针对一组算法,将每一个算法 ...

  3. Eclipse Sort Members默认之后恢复的方法

    alt+shift+s -- > m CRLF 默认一种排序之后,对话框就再也出不来了: 使用这样的方法: window - preference - Java | Java dialogs | ...

  4. HDU3790

    最短路径问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  5. 【python基础】 Tkinter 之 几何管理器

    Tkinter支持三种几何管理器:网格管理器,包管理器,位置管理器 提示:由于每个管理器都有自己放置小构件的风格,最好不要在同一个容器中的小构件使用多个管理器.可以使用框架作为子容器以获取期望的布局. ...

  6. WinForm 文件操作

    文件及文件夹操作 C/S:WinForm可以操作客户端文件 Client ServerB/S:浏览器服务 Brower Server 命名空间:using system .IO; 1. File类:文 ...

  7. 启动activity与使用Intent通信机制解析

    我们都知道,一个activity启动另一个activity最简单的方式就是使用startActivity方法: public void startActivity (Intent intent) 但是 ...

  8. shell编程其实真的很简单(三)

    通过前两篇文章,我们掌握了shell的一些基本写法和变量的使用,以及基本数据类型的运算.那么,本次就将要学习shell的结构化命令了,也就是我们其它编程语言中的条件选择语句及循环语句. 不过,在学习s ...

  9. 详解Google Chrome浏览器(操作篇)(一)

    开篇概述 在上篇博客中详解Google Chrome浏览器(理论篇)一文中,主要讲解了Chrome 搜索引擎使用.Chrome安装和基本操作.Chrome 基本架构.多线程等原理性问题,这篇将重点讲解 ...

  10. [转]CentOS 6.3下Samba服务器的安装与配置

    一.简介 Samba是一个能让Linux系统应用Microsoft网络通讯协议的软件,而SMB是Server Message Block的缩写,即为服务器消息块 ,SMB主要是作为Microsoft的 ...