zoukankan      html  css  js  c++  java
  • ios UIImagePickerController简单说明

    首先,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]; }
  • 相关阅读:
    The executable was signed with invalid entitlements
    iOS7 文本转语音 AVSpeechSynthesizer
    The document "ViewController.xib" could not be opened. Could not read archive.
    UIPanGestureRecognizer
    UINavigationController
    IE6下面的css调试工具
    15款最好的网站音乐播放器
    ASP.NET常用加密解密方法
    ASP.NET根据IP获取省市地址
    强悍的CSS工具组合:Blueprint, Sass, Compass
  • 原文地址:https://www.cnblogs.com/chaochaobuhuifei55/p/5396605.html
Copyright © 2011-2022 走看看