系统相机的调用(只能真机试验)

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. #pragma  mark - 相机调用拍照  
  2. - (void)didClickRightButton{  
  3.   
  4.     if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {  
  5.           
  6.         UIImagePickerController * cameraPicker = [[UIImagePickerController alloc] init];  
  7.         cameraPicker.delegate = self;  
  8.         cameraPicker.allowsEditing = YES;  
  9.         cameraPicker.sourceType = UIImagePickerControllerSourceTypeCamera;  
  10.         //  相机的调用为照相模式  
  11.         cameraPicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;  
  12.         //  设置为NO则隐藏了拍照按钮  
  13.         cameraPicker.showsCameraControls = YES;  
  14.         //  设置相机摄像头默认为前置  
  15.         cameraPicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;  
  16.         //  设置相机闪光灯开关  
  17.         cameraPicker.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto;  
  18.         //  用来设置覆盖在你照相图像上,可以自定义位置或图片(类似美图秀秀加个小猫小狗小花修饰)  
  19.         //cameraPicker.cameraOverlayView  
  20.         //  用来修改拍照相框  
  21.         //cameraPicker.cameraViewTransform  
  22.         [self presentViewController:cameraPicker animated:YES completion:nil];  
  23.         [cameraPicker release];  
  24.           
  25.     } else {  
  26.           
  27.         NSLog(@"当前设备不支持相机调用");  
  28.           
  29.     }  
  30.   
  31. }  
  32.   
  33. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{  
  34.   
  35.     /*-------------------------------相机拍照--------------------------------------*/  
  36.     if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {  
  37.           
  38.         UIImage * image = [info objectForKey:UIImagePickerControllerOriginalImage];  
  39.         _imageView.image = image;  
  40.         [self dismissViewControllerAnimated:YES completion:^{  
  41.         }];  
  42.           
  43.     } else if (picker .sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {  
  44.           
  45.         /** 
  46.          *  UIImagePickerControllerEditedImage 取得的是被编辑过的图片,需要allowsEditing设置为YES 
  47.          *  UIImagePickerControllerOriginalImage 取得的是相册中原始图片 
  48.          */  
  49.         UIImage * image = [info objectForKey:UIImagePickerControllerOriginalImage];  
  50.         _imageView.image = image;  
  51.         [self dismissViewControllerAnimated:YES completion:nil];  
  52.     }  
  53.   
  54.     /*-------------------------------相机录像--------------------------------------*/  
  55.     if (picker.cameraCaptureMode == UIImagePickerControllerCameraCaptureModeVideo) {  
  56.           
  57.         //  获得视频路径  
  58.         NSURL *url = [info objectForKey:UIImagePickerControllerMediaURL];  
  59.         //  存储视频(@selector里面的方法一定要是这种格式)  
  60.         UISaveVideoAtPathToSavedPhotosAlbum([url path], self@selector(video:didFinishSavingWithError: contextInfo:), nil);  
  61.         [self dismissViewControllerAnimated:YES completion:nil];  
  62.           
  63.     }else if(picker.cameraCaptureMode == UIImagePickerControllerCameraCaptureModePhoto){  
  64.     }  
  65.       
  66. }  
  67.   
  68. - (void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(voidvoid *)contextInfo{  
  69.      
  70.     NSLog(@"%s",__FUNCTION__);  
  71. }  
  72.   
  73. #pragma mark - 相机调用拍视频  
  74. - (void)didClickLeftButton{  
  75.       
  76.     BOOL judge = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary];  
  77.     if (judge) {  
  78.           
  79.         UIImagePickerController * cameraPicker = [[UIImagePickerController alloc] init];  
  80.         cameraPicker.delegate = self;  
  81.         cameraPicker.sourceType = UIImagePickerControllerSourceTypeCamera;  
  82.         //  视频录制的规定时间  
  83.         //  cameraPicker.videoMaximumDuration = 10;  
  84.         //  引入 MobileCoreServices.framework 库, 设置viedo依托的.media  
  85.         //  这句话必须放在设置cameraCaptureMode前面,涉及到一个API执行顺序问题  
  86.         cameraPicker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];  
  87.         //  相机调用为录像模式  
  88.         cameraPicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;  
  89.         [self presentViewController:cameraPicker animated:YES completion:nil];  
  90.           
  91.     } else {  
  92.           
  93.         NSLog(@"当前设备不支持相机的调用");  
  94.           
  95.     }  
  96. }  
  97.   
  98. - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{  
  99.   
  100.    [self presentViewController:cameraPicker animated:YES completion:nil];  
  101.     NSLog(@"%s",__FUNCTION__);  
  102. }  


@细心的朋友可能会发现,明明设置里面是中文,调用的相机显示的标题仍然是英文,如何把如cancel->取消


这样就OK了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值