码迷,mamicode.com
首页 > 移动开发 > 详细

ios UIImagePickerController简单说明

时间:2016-04-15 20:14:16      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:

首先,VC中添加#import <MobileCoreServices/MobileCoreServices.h> 使用(NSString *) kUTTypeImage定义在其中

判断是否授权:

 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]; }

 

ios UIImagePickerController简单说明

标签:

原文地址:http://www.cnblogs.com/chaochaobuhuifei55/p/5396605.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!