zoukankan      html  css  js  c++  java
  • UIImagePickerController

      1 1.+(BOOL)isSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType;                 检查指定源是否在设备上可用。
      2 //检查照片源是否可用
      3 [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]2.allowsEditing 默认NO
      4 是否允许编辑
      5 允许编辑.
      6 [imagePicker setAllowsEditing:YES]; 
      7 3. videoMaximumDuration
      8 
设置UIImagePicker的最大视频持续时间.默认10分钟
      9 4. + availableMediaTypesForSourceType: // 指定源可用的媒体种类
     10  //获得相机模式下支持的媒体类型
     11 NSArray* availableMediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
     12 5. sourceType
     13 设置UIImagePicker照片源类型,默认有3种。
     14 照片源类型
     15  
     16  UIImagePickerControllerSourceTypeCamera            照相机
     17  UIImagePickerControllerSourceTypePhotoLibrary      照片库(通过同步存放的,用户不能删除)
     18  UIImagePickerControllerSourceTypeSavedPhotosAlbum  保存的照片(通过拍照或者截屏保存的,用户可以删除)
     19 
     20 6.UIImagePicker使用步骤:
     21 
    检查指定源是否可用. 
     22 isSourceTypeAvailable:方法.
    
     23 检查可用媒体(视频还是只能是图片) availableMediaTypesForSourceType:方法.
    
     24 设置界面媒体属性
     25 mediaTypes property.
    
     26 显示界面使用
     27 presentViewController:animated:completion:方法.
     28 iPad中是popover形式.需要确保sourceType有效. 
    
     29 相关操作,移除视图. 


如果想创建一个完全自定义界面的image picker来浏览图片,使用 
     30 Assets Library Framework Reference中的类. (AV Foundation Programming Guide 中的 “Media Capture and Access to Camera” )

 


     31 7.设置源

     32 
    + availableMediaTypesForSourceType: // 指定源可用的媒体种类
    + isSourceTypeAvailable: // 指定源是否在设备上可用
      sourceType 

// 运行相关接口前需要指明源类型.必须有效,否则抛出异常. picker已经显示的时候改变这个值,picker会相应改变来适应.默认 UIImagePickerControllerSourceTypePhotoLibrary.


     33 8.设置picker属性

     34 
      allowsEditing //是否可编辑      
     35 delegate 
      mediaTypes 

// 指示picker中显示的媒体类型.设置每种类型之前应用availableMediaTypesForSourceType:检查一下.如果为空或者array中类型都不可用,会发生异常.默认 kUTTypeImage, 只能显示图片.
    

     36 9.video选取参数
     37 

      videoQuality //视频拍摄选取时的编码质量.只有mediaTypes包含kUTTypeMovie时有效.      
     38 videoMaximumDuration //秒,video最大记录时间,默认10分钟.只用当mediaTypes包含kUTTypeMovie时有效. 


     39 10.自定义界面
     40 

      showsCameraControls 

// 指示 picker 是否显示默认的camera controls.默认是YES,设置成NO隐藏默认的controls来使用自定义的overlay view.(从而可以实现多选而不是选一张picker就dismiss了).只有 UIImagePickerControllerSourceTypeCamera源有效,否则NSInvalidArgumentException异常.
      
     41 cameraOverlayView 

//自定义的用于显示在picker之上的view.只有当源是UIImagePickerControllerSourceTypeCamera时有效.其他时候使用抛出NSInvalidArgumentException异常.
      
     42 cameraViewTransform 

//预先动画.只影响预先图像,对自定义的overlay view和默认的picker无效.只用当picker的源是UIImagePickerControllerSourceTypeCamera时有效,否则NSInvalidArgumentException异常.


     43 11.选取媒体
     44 

    – takePicture 

//使用摄像头选取一个图片。自定义overlay可以多选。已经有图片正在选取是调用无效,必须要等delegate收到 imagePickerController:didFinishPickingMediaWithInfo:消息后才能再次选取。非UIImagePickerControllerSourceTypeCamera源会导致异常。
    
     45 – startVideoCapture 

    
     46 – stopVideoCapture 

//结束视频选取,之后系统调用delegate的 imagePickerController:didFinishPickingMediaWithInfo:方法。


     47 12.设置摄像头
     48 
      cameraDevice //使用的镜头(默认后置的)    
     49 + isCameraDeviceAvailable: // 摄像设备是否可用.   
     50  + availableCaptureModesForCameraDevice: // 设备可用的选取模式 
      cameraCaptureMode //相机捕获模式      
     51 cameraFlashMode //闪光灯模式(默认自动)    
     52 + isFlashAvailableForCameraDevice: // 是否有闪光能力


     53 13.UIImagePickerControllerDelegate 
     54 使用UIImageWriteToSavedPhotosAlbum保存图像, UISaveVideoAtPathToSavedPhotosAlbum保存视频. 4.0后使用writeImageToSavedPhotosAlbum:metadata:completionBlock:保存元数据.

    
     55 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info


     56 //包含选择的图片或者一个视频的URL,详见“Editing Information Keys.”


     57 //如果是设置可编辑属性,那么picker会预显示选中的媒体,编辑后的与初始的都会保存在info中.
    
     58 – imagePickerControllerDidCancel:
    
     59 -imagePickerController:didFinishPickingImage:editingInfo://Deprecated in iOS 3.0

NSString *const UIImagePickerControllerMediaType;// 媒体类型
NSString *const UIImagePickerControllerOriginalImage;// 原始未编辑的图像
NSString *const UIImagePickerControllerEditedImage;// 编辑后的图像
NSString *const UIImagePickerControllerCropRect;// 源图像可编辑(有效?)区域
NSString *const UIImagePickerControllerMediaURL;// 视频的路径
NSString *const UIImagePickerControllerReferenceURL;// 原始选择项的URL
NSString *const UIImagePickerControllerMediaMetadata;// 只有在使用摄像头并且是图像类型的时候有效.包含选择图像信息的字典类型 60 14. UIImagePickerController小例子
     61 UIImagePickerController的代理需要遵守这两个协议.<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
     62 
     63 #pragma mark 选择照片
     64 - (void)selectPhoto
     65 {
     66     // 1. 首先判断照片源是否可用
     67     if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
     68         
     69         // 0)实例化控制器
     70         UIImagePickerController *picker = [[UIImagePickerController alloc]init];
     71         // 1)设置照片源
     72         [picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
     73         
     74         // 2) 设置允许修改
     75         [picker setAllowsEditing:YES];
     76         // 3) 设置代理
     77         [picker setDelegate:self];
     78         // 4) 显示控制器
     79         [self presentViewController:picker animated:YES completion:nil];
     80         
     81     } else {
     82         NSLog(@"照片源不可用");
     83     }
     84     
     85 }
     86 
     87 #pragma mark - imagePicker代理方法
     88 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
     89 {
     90     UIImage *image = info[@"UIImagePickerControllerEditedImage"];
     91     [_imageButton setImage:image forState:UIControlStateNormal];
     92     
     93     // 关闭照片选择器
     94     [self dismissViewControllerAnimated:YES completion:nil];
     95     
     96     // 需要将照片保存至应用程序沙箱,由于涉及到数据存储,同时与界面无关
     97     // 可以使用多线程来保存图像
     98     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
     99         
    100         // 保存图像
    101         // 1. 取图像路径
    102         NSArray *docs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    103         NSString *imagePath = [docs[0]stringByAppendingPathComponent:@"abc.png"];
    104         
    105         // 2. 转换成NSData保存
    106         NSData *imageData = UIImagePNGRepresentation(image);
    107         [imageData writeToFile:imagePath atomically:YES];
    108     });
    109 }
  • 相关阅读:
    Jdk1.8 HashMap源码分析
    瘦身部署应用
    Redis 创建和使用集群(yum方式安装低版本)
    Redis 创建和使用集群
    记录一下
    Oracle 开发人员权限控制
    Linux 免密登录远程服务器及执行相关命令
    Oracle 连接表空间并执行SQL文件
    MySQL 8.0.13安装教程(windows 64位) (转)
    scrapy中Selector的使用
  • 原文地址:https://www.cnblogs.com/developer-wang/p/4527058.html
Copyright © 2011-2022 走看看