UIImagePickerController拍照/相册/录像/本地视频
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拍照/相册/录像/本地视频的更多相关文章
- swift2.0 UIImagePickerController 拍照 相册 录像
系统 ios9.1 语言swift2.0 在app 里最常用的功能就是多媒体选择,首先我们storyboard 创建一个button 用于触发选择事件 @IBAction func selectIma ...
- ios本地相册 照像 本地视频
-(IBAction)btnClick{ UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate: ...
- Swift - 从相册中选择视频(过滤掉照片,使用UIImagePickerController)
(本文代码已升级至Swift4) 有时我们需要从系统相册中选择视频录像,来进行编辑或者上传操作,这时使用 UIImagePickerController 就可以实现. 默认情况下,UIImagePic ...
- 照相、从相册上取照片、播放音频、播放本地视频、播放网络视频、MPMoviePlayerController
一.照相.从相册上去照片 1. 先判断是否支持照相功能 *判断当前设备是否支持照相功能,支持返回YES 否则返回NO 注意:模拟器不支持照相功能 把握一个原则只要是物理硬件相关的功能模拟器都不支持 例 ...
- IOS UIImagePickerController(拍照或者读取相册)
UIImagePickerController ● 使用UIImagePickerController就可以进行拍照或者读取相册 ● 通过sourceType属性来决定拍照还是读取相册 ➢ UII ...
- 案例分享:Qt+Arm基于RV1126平台的内窥镜软硬整套解决方案(实时影像、冻结、拍照、录像、背光调整、硬件光源调整,其他产品也可使用该平台,如视频监控,物联网产品等等)
自研产品系列方案 1. 基于瑞芯微的 RV1126 芯片平台: 2. 外接 USB 摄像头(OV9734. OV6946.OV2740 等 UVC 模块)作为图像输入源: 3. 可通过 LED ...
- Android 开发 Camera类的拍照与录像
前言 在开发Android应用的时候,如果需要调用摄像头拍照或者录像,除了通过Intent调用系统现有相机应用进行拍照录像之外,还可以通过直接调用Camera硬件去去获取摄像头进行拍照录像的操作.本篇 ...
- 真正可用的安卓webview html图片上传限制突破处理(拍照+相册都可以用)
两篇起步使用webview参考文章,第一篇解除限制,但会调用外部浏览器打开链接,第二篇 覆盖shouldOverrideUrlLoading return true https://www.jb51. ...
- 项目实战:Qt+Ffmpeg+OpenCV相机程序(打开摄像头、支持多种摄像头、分辨率调整、翻转、旋转、亮度调整、拍照、录像、回放图片、回放录像)
若该文为原创文章,未经允许不得转载原博主博客地址:https://blog.csdn.net/qq21497936原博主博客导航:https://blog.csdn.net/qq21497936/ar ...
随机推荐
- plsql developer日期时间格式设置
1 工具->首选项->日期/时间都使用windows格式: 2 在环境变量加入 nls_date_format=YYYY-MM-DD HH24:MI:SS nls_timestamp_fo ...
- NSNotificationCenter机制
作用:NSNotificationCenter是专门供程序中不同类间的消息通信而设置的. 注册通知:即要在什么地方接受消息 [[NSNotificationCenter defaultCenter] ...
- Canvas 颜色反转
ImageData中的元素反转颜色 255-data[i,i+1,i+2] <!DOCTYPE html> <html lang="en"> <hea ...
- html标签大全(1)
http标签详解及讲解 1.基础标签 <!DOCTYPE html> <!--表示文本类型--> <html> <!--<html> ...
- Crystal框架配置参数加载机制详解?
前言 定义 配置参数定义的形式 配置参数文件定义在哪里? 配置参数加载的优先级 如何使用配置参数? 最佳实践 Jar项目中如何定义配置参数? War项目中如何定义或重载Jar包中的配置参数? 开发人员 ...
- 【Android】 分享一个完整的项目,适合新手!
写这个app之前是因为看了头条的一篇文章:http://www.managershare.com/post/155110,然后心想要不做一个这样的app,让手机计算就行了.也就没多想就去开始整了. ...
- IIS7上搭建网站的基本方法(系统推荐的安全方案)
1.创建的程序池命名默认为网站名称,程序池的标识采用默认的ApplicationPoolIdentity,这个会自动生成虚拟的用户,系统推荐的安全方案: 2.网站右键 基本设置 --> 连接为 ...
- 使用jmeter进行APP接口测试经验总结
声明:我觉得文章不错想保存,如果带来不便请联系我. 使用工具: Fiddler.Jmeter 测试步骤: 1. 确认接口 从开发人员那里获取接口文档,接口文档应该包括完整的功能接口.接口请求方式 ...
- Python2.7学习笔记-定义函数、filter/map/reduce/lambda
我把写的代码直接贴在下面了,注释的不是很仔细,主要是为了自己复习时方便查找,并不适合没有接触过python的人看,其实我也是初学者. #定义函数 def my_abs(x): if x>=0: ...
- 【CNMP系列】CentOS7.0下安装Nginx服务
话步前言,CNMP之路,系统起步:http://www.cnblogs.com/riverdubu/p/6425028.html 这回我来讲解下CentOS7.0下如何安装和配置Nginx服务 Ngi ...