UIImagePickerController 获取相片视频
1.UIImagePickerController的静态方法:
imagepicker = [[UIImagePickerController alloc]init];
//UIImagePickerController静态方法判断设备是否支持照相机/图片库/相册功能
/*
typedef NS_ENUM(NSInteger, UIImagePickerControllerSourceType) {
UIImagePickerControllerSourceTypePhotoLibrary,
UIImagePickerControllerSourceTypeCamera,
UIImagePickerControllerSourceTypeSavedPhotosAlbum
};
*/
BOOL isCameraSupport = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
NSLog(@"support camera:%d",isCameraSupport);
//UIImagePickerController静态方法判断设备是否支持前置摄像头/后置摄像头
/*
typedef NS_ENUM(NSInteger, UIImagePickerControllerCameraDevice) {
UIImagePickerControllerCameraDeviceRear,
UIImagePickerControllerCameraDeviceFront
};
*/
BOOL isRearSupport = [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear];
NSLog(@"rear support:%d",isRearSupport);
//UIImagePickerController静态方法判断设备是否支持前置摄像头闪光灯/后置摄像头闪光灯
/*
typedef NS_ENUM(NSInteger, UIImagePickerControllerCameraDevice) {
UIImagePickerControllerCameraDeviceRear,
UIImagePickerControllerCameraDeviceFront
};
*/
BOOL isFlushSupport = [UIImagePickerController isFlashAvailableForCameraDevice:UIImagePickerControllerCameraDeviceRear];
NSLog(@"rear flash support:%d",isFlushSupport);
//UIImagePickerController静态方法返回前置摄像头/后置摄像头支持的拍摄类型
/*
typedef NS_ENUM(NSInteger, UIImagePickerControllerCameraDevice) {
UIImagePickerControllerCameraDeviceRear,
UIImagePickerControllerCameraDeviceFront
};
*/
//返回类型有照片和视频
/*
enum {
UIImagePickerControllerCameraCaptureModePhoto,
UIImagePickerControllerCameraCaptureModeVideo
};
typedef NSUInteger UIImagePickerControllerCameraCaptureMode;
*/
NSArray* captureModes = [UIImagePickerController availableCaptureModesForCameraDevice:UIImagePickerControllerCameraDeviceRear];
for (NSNumber* mode in captureModes) {
NSLog(@"capture modes:%d",[mode integerValue]);
}
//UIImagePickerController静态方法返回照相机/相册/照片库所支持的媒体类型
/*
typedef NS_ENUM(NSInteger, UIImagePickerControllerSourceType) {
UIImagePickerControllerSourceTypePhotoLibrary,
UIImagePickerControllerSourceTypeCamera,
UIImagePickerControllerSourceTypeSavedPhotosAlbum
};
*/
//返回类型有kUTTypeMovie,kUTTypeImage,其他类型均在<MobileCoreServices/MobileCoreServices.h>下
NSArray* mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
for (NSString* type in mediaTypes) {
NSLog(@"media types:%@",type);
}
2.UIImagePickerController属性详解:
//指定使用照相机模式,可以指定使用相册/照片库
imagepicker.sourceType = UIImagePickerControllerSourceTypeCamera;
//设置当拍照完或在相册选完照片后,是否跳到编辑模式进行图片剪裁。只有当showsCameraControls属性为true时才有效果
imagepicker.allowsEditing = YES;
//设置拍照时的下方的工具栏是否显示,如果需要自定义拍摄界面,则可把该工具栏隐藏
imagepicker.showsCameraControls = YES;
//设置使用后置摄像头,可以使用前置摄像头
imagepicker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
//设置闪光灯模式
/*
typedef NS_ENUM(NSInteger, UIImagePickerControllerCameraFlashMode) {
UIImagePickerControllerCameraFlashModeOff = -1,
UIImagePickerControllerCameraFlashModeAuto = 0,
UIImagePickerControllerCameraFlashModeOn = 1
};
*/
imagepicker.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto;
//设置相机支持的类型,拍照和录像
imagepicker.mediaTypes = @[(NSString*)kUTTypeImage,(NSString*)kUTTypeMovie];
//设置拍摄时屏幕的view的transform属性,可以实现旋转,缩放功能
// imagepicker.cameraViewTransform = CGAffineTransformMakeRotation(M_PI*45/180);
// imagepicker.cameraViewTransform = CGAffineTransformMakeScale(1.5, 1.5);
//所有含有cameraXXX的属性都必须要sourceType是UIImagePickerControllerSourceTypeCamera时设置才有效果,否则会有异常
//设置UIImagePickerController的代理
imagepicker.delegate = self;
-(void)showCamera{
//用模态方式呈现imagepicker
[self presentModalViewController:imagepicker animated:YES];
}
使用 imagepicker.cameraViewTransform = CGAffineTransformMakeRotation(M_PI*45/180);旋转45度的效果:
使用imagepicker.cameraViewTransform = CGAffineTransformMakeScale(1.5, 1.5);全屏的效果,同时imagepicker.showsCameraControls =NO;隐藏工具栏:
使用imagepicker.allowsEditing = YES;出现的图片编辑效果,只有当imagepicker.showsCameraControls = YES;才有效果:
使用 imagepicker.mediaTypes = @[(NSString*)kUTTypeImage,(NSString*)kUTTypeMovie];支持拍照和视频的前后对比效果:
3.UIImagePickerController回调详解:
//成功获得相片还是视频后的回调
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
//通过UIImagePickerControllerMediaType判断返回的是照片还是视频
NSString* type = [info objectForKey:UIImagePickerControllerMediaType];
//如果返回的type等于kUTTypeImage,代表返回的是照片,并且需要判断当前相机使用的sourcetype是拍照还是相册
if ([type isEqualToString:(NSString*)kUTTypeImage]&&picker.sourceType==UIImagePickerControllerSourceTypeCamera) {
//获取照片的原图
UIImage* original = [info objectForKey:UIImagePickerControllerOriginalImage];
//获取图片裁剪的图
UIImage* edit = [info objectForKey:UIImagePickerControllerEditedImage];
//获取图片裁剪后,剩下的图
UIImage* crop = [info objectForKey:UIImagePickerControllerCropRect];
//获取图片的url
NSURL* url = [info objectForKey:UIImagePickerControllerMediaURL];
//获取图片的metadata数据信息
NSDictionary* metadata = [info objectForKey:UIImagePickerControllerMediaMetadata];
//如果是拍照的照片,则需要手动保存到本地,系统不会自动保存拍照成功后的照片
UIImageWriteToSavedPhotosAlbum(edit, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}else{
}
//模态方式退出uiimagepickercontroller
[imagepicker dismissModalViewControllerAnimated:YES];
}
//取消照相机的回调
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
//模态方式退出uiimagepickercontroller
[imagepicker dismissModalViewControllerAnimated:YES];
}
//保存照片成功后的回调
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error
contextInfo:(void *)contextInfo{
NSLog(@"saved..");
}
4.自定义相机拍照画面:
//设置拍照时的下方的工具栏是否显示,如果需要自定义拍摄界面,则可把该工具栏隐藏
imagepicker.showsCameraControls = NO;
UIToolbar* tool = [[UIToolbar alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height-55, self.view.frame.size.width, 75)];
tool.barStyle = UIBarStyleBlackTranslucent;
UIBarButtonItem* cancel = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelCamera)];
UIBarButtonItem* add = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(savePhoto)];
[tool setItems:[NSArray arrayWithObjects:cancel,add, nil]];
//把自定义的view设置到imagepickercontroller的overlay属性中
imagepicker.cameraOverlayView = tool;
-(void)cancelCamera{
[imagepicker dismissModalViewControllerAnimated:YES];
}
-(void)savePhoto{
//拍照,会自动回调- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info,对于自定义照相机界面,拍照后回调可以不退出实现连续拍照效果
[imagepicker takePicture];
}
5.UIImagePickerController是继承UINavigationController,所以可以push和pop一些viewcontroller进行导航效果。例如,自定义照相机画面的时候可以在拍摄完后push一个viewcontroller用于对照片进行编辑。
UIImagePickerController 获取相片视频的更多相关文章
- Android开发之获取本地视频和获取自拍视频
1.获取本地所有视频 public void getLoadMedia() { Cursor cursor = UILApplication.instance.getApplicationContex ...
- iOS 直播-获取音频(视频)数据
iOS 直播-获取音频(视频)数据 // // ViewController.m // capture-test // // Created by caoxu on 16/6/3. // Copyri ...
- 怎样获取HTML5视频的持续时间
HTML5视频的Bigger体验是非常令人振奋的,非常easy的道理,不用载入和依赖烦人的Flash或其它第三方插件来播放视频,也是大功一件.我们能够通过自己定义控件对视频进行显示和操控,当中一个常见 ...
- iOS - 获取音视频文件的Metadata信息
// // MusicInfoArray.h // LocationMusic // // Created by Wengrp on 2017/6/22. // Copyright © 2017年 W ...
- 获取音视频文件AVMetadata数据
获取音视频文件AVMetadata数据 问题来源: http://stackoverflow.com/questions/16318821/extracting-mp3-album-artwork-i ...
- php获取YouTube视频信息的方法
YouTube的视频地址格式https://www.youtube.com/watch?v=[VIDEO_ID]例子:https://www.youtube.com/watch?v=psvkyf3Pz ...
- DirectShow 获取音视频输入设备列表
开发环境:Win10 + VS2015 本文介绍一个 "获取音频视频输入设备列表" 的示例代码. 效果图 代码下载 代码下载(VC2015):Github - DShow_simp ...
- UIImagePickerController本地图片视频,相机录像机使用
1.添加framework:MobileCoreServices 2.头:#import <MobileCoreServices/MobileCoreServices.h> 大致代码: U ...
- 获取youku视频下载链接(wireshark抓包分析)
随便说两句 前两天写了一个python脚本,试图以分析网页源码的方式得到优酷视频的下载地址,结果只得到视频的纯播放地址,下载纯播放地址得到的文件也无法正常播放视频. 这里共享一下播放地址得到的方法(想 ...
随机推荐
- quick Cocos2dx lua 接anysdk
quick3.3 的quick\samples\anysdk中有例子,具体用法可以参考官方文档,将的非常详细. 1.框架接口设计 系统介绍 必接入流程简要描述 消息通知 可扩展性 测试模式 添加测试账 ...
- [课程设计]Scrum 1. 9 多鱼点餐系统开发进度(最后页面完善&修复BUG&用户测试反馈)
[课程设计]Scrum 1. 9 多鱼点餐系统开发进度(最后页面完善&修复BUG&用户测试) 1.团队名称:重案组 2.团队目标:长期经营,积累客户充分准备,伺机而行 3.团队口号:矢 ...
- Script 简单语句的练习题
猜拳 <body>请输入剪刀或者石头或者布:<br /><input type="text" id="A"/><inp ...
- 隐式意图Intent
在我们想往下一个页面传递数据时,要想到显式意图和隐式意图,显示意图用于内部活动跳转时比较方便,而隐式意图用于应用程序中外部活动的跳转时较为方便,在使用隐式意图时我们要想到清单文件 代码如下: < ...
- 规则引擎以及blaze 规则库的集成初探之三——Blaze规则引擎和SRL
原文地址:http://jefferson.iteye.com/blog/68604 在上面介绍利用JSR94的api使用的章节中,我们使用的具体引擎的实现是一个商业产品,如果想了解Drools的使用 ...
- SE78、SWM0
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- INPUT只能输入数字
input只能输入数字: (只能输入数字,并且输入的值不能大于99),但是这样有个问题,就是当输入非数字字符时,输入框中所有的字符都会被清除 <input type="text&quo ...
- composer安装fxp插件时候提示内存不足且没有交换空间的解决办法
The following exception is caused by a lack of memory and not having swap Check https://getcomposer. ...
- linux详细redis安装和php中redis扩展
第一部分:安装redis 希望将redis安装到此目录 1 /usr/local/redis 希望将安装包下载到此目录 1 /usr/local/src 那么安装过程指令如下: 1 2 3 4 5 6 ...
- jQuery学习笔记整理
一.子元素选择器.:nth-child:匹配父元素下的第N个子或者奇偶元素.注意:序号是从1开始的,而eq是从0开始计数的!它匹配的是前方选择器选择到的元素的父元素下面的第几个元素.例如:ul li: ...