ios UIImagePickerController简单说明
2016-04-15 19:07
513 查看
首先,VC中添加#import <MobileCoreServices/MobileCoreServices.h> 使用(NSString *) kUTTypeImage定义在其中
判断是否授权:
AVAuthorizationStatusNotDetermined = 0,//未明确
AVAuthorizationStatusRestricted,//受限
AVAuthorizationStatusDenied,//不允许
AVAuthorizationStatusAuthorized//允许
第一种使方法照相机:
第二种使用摄像机:
第三种使用相册取图片类型:
第四种使用相册取视频类型:
代理:
判断是否授权:
NSString *mediaType = AVMediaTypeVideo;// Or AVMediaTypeAudio AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
AVAuthorizationStatusNotDetermined = 0,//未明确
AVAuthorizationStatusRestricted,//受限
AVAuthorizationStatusDenied,//不允许
AVAuthorizationStatusAuthorized//允许
第一种使方法照相机:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; //添加代理 imagePicker.delegate = self; //是否允许编辑 imagePicker.allowsEditing = YES; //资源类型 imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; //media类型 imagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeImage, nil]; //转跳 [self presentModalViewController:imagePicker animated:YES];
第二种使用摄像机:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; imagePicker.delegate = self; imagePicker.allowsEditing = YES; imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; //media类型 imagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil]; //视频品质 imagePicker.videoQuality = UIImagePickerControllerQualityTypeLow; [self presentModalViewController:imagePicker animated:YES];
第三种使用相册取图片类型:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; imagePicker.delegate = self; imagePicker.allowsEditing = YES; imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; imagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *)kUTTypeImage, nil]; [self presentModalViewController:imagePicker animated:YES];
第四种使用相册取视频类型:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; imagePicker.delegate = self; imagePicker.allowsEditing = YES; imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; imagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil]; [self presentModalViewController:imagePicker animated:YES];
代理:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { if ([[info objectForKey:UIImagePickerControllerMediaType] isEqualToString:(NSString*)kUTTypeImage]) { //获取照片的原图 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 if ([[info objectForKey:UIImagePickerControllerMediaType] isEqualToString:(NSString*)kUTTypeMovie]) { NSString *videoPath = [[info objectForKey:UIImagePickerControllerMediaURL] path]; self.fileData = [NSData dataWithContentsOfFile:videoPath]; } [picker dismissModalViewControllerAnimated:YES]; } - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { [picker dismissModalViewControllerAnimated:YES]; }
相关文章推荐
- MUI_Ajax
- requests的介绍和学习
- UI控件--RecyclerView(1)
- UITextField实现过滤选中状态拼音
- OC_实现UITableviewCell之间的间距
- UILabel自动调整大小(高度,宽度)
- OC_UITableviewCell左滑操作
- UI控件--CardView
- 【Arduino官方教程第一辑】示例程序-目录
- Druid数据库连接池使用
- [iOS]UITableView添加通过xib创建的headerView坑爹问题
- fsck.ext4 unable to resolve 'UUID=a4a7...'
- No 'Access-Control-Allow-Origin' header is present on the requested resource.
- 334. Increasing Triplet Subsequence 动态规划
- generic_make_request函数初探
- YUI api压缩 js/css
- easy touch利用playmaker拖动ngui对象
- iOS中关于UIButton缩进问题
- easyui 初始加载时页面样式乱的解决方法
- 【转】面试题:实现一个队列,这个队列除了有EnQueue, DeQueue操作,还有一个Max操作,三个操作复杂度都是O(1)