UIImagePickerViewController裁切头像

我采用的是系统的方法,没有自定义界面


//拍照

- (void)takePhoto

{

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

        UIImagePickerController *picker = [[UIImagePickerController alloc] init];

        picker.delegate = self;

        picker.allowsEditing = YES;

        picker.sourceType = UIImagePickerControllerSourceTypeCamera;

        [self presentViewController:picker animated:YES completion:nil];

    } else {

        [[UIAlertView alertViewWithTitle:@"提示" message:@"当前设备相机不可用" buttonTitles:@[@"确定"] callback:^(UIAlertView *alertView, NSInteger buttonIndex) {

            

        }] show];

    }

}


//从相册选择

- (void)loadLocal

{

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];

    picker.delegate = self;

    picker.allowsEditing = YES;

    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    [self presentViewController:picker animated:YES completion:nil];

    

}



代理方法:

#pragma mark - UIImagePickerControllerDelegate


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

{

/**

选取的信息都在info里面

键值:

NSString *const  UIImagePickerControllerMediaType ;指定用户选择的媒体类型
NSString *const  UIImagePickerControllerOriginalImage ;原始图片
NSString *const  UIImagePickerControllerEditedImage ;裁剪之后的图片
NSString *const  UIImagePickerControllerCropRect ;裁剪尺寸
NSString *const  UIImagePickerControllerMediaURL ;媒体的URL
NSString *const  UIImagePickerControllerReferenceURL ;原件的URL
NSString *const  UIImagePickerControllerMediaMetadata;当来数据来源是照相机的时候这个值才有效

*/

    UIImage *editedImage = info[UIImagePickerControllerEditedImage];

    

    [self updatePortraitWithImage:editedImage];

    [picker dismissViewControllerAnimated:YES completion:^{

        

    }];

}



- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker

{

    

    [picker dismissViewControllerAnimated:YES completion:nil];

    

}


相片来源:
enum {
    UIImagePickerControllerSourceTypePhotoLibrary , //来自图库
    UIImagePickerControllerSourceTypeCamera , //来自相机
    UIImagePickerControllerSourceTypeSavedPhotosAlbum  //来自相册
};

检测设备是否可用

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
     {
         NSLog(@ "支持相机" );
     }
     if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
     {
         NSLog(@ "支持图库" );
     }
     if  ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum])
     {
         NSLog(@ "支持相片库" );
     }



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值