`

iOS 获取相册原图

    博客分类:
  • ios
 
阅读更多

 

//原图上传

- (void)addimg {

    UIAlertController *alertController = [UIAlertControlleralertControllerWithTitle:@"请选择"message:nilpreferredStyle:UIAlertControllerStyleActionSheet];

    UIAlertAction *cancelAction = [UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleCancelhandler:nil];

    UIAlertAction *CameraAction = [UIAlertActionactionWithTitle:@"相机"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction * _Nonnull action) {

//        [self persentImagePicker:1];

    }];

    UIAlertAction *AlbumAction = [UIAlertActionactionWithTitle:@"相册"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction * _Nonnull action) {

//        [self persentImagePicker:2];

    }];

    

    

    

    [alertController addAction:CameraAction];

    [alertController addAction:AlbumAction];

    [alertController addAction:cancelAction];

    [selfpresentViewController:alertController animated:YEScompletion:nil];

}

 

//调用本地相册

-(void)persentImagePicker:(int)type{

    if(!_imagePickerG){

        //初始化相机

        _imagePickerG = [[UIImagePickerControlleralloc]init];

        //代理

        _imagePickerG.delegate = self;

    }

    if(type == 1){

        //相机

        _imagePickerG.sourceType = UIImagePickerControllerSourceTypeCamera;

        _imagePickerG.allowsEditing = YES;

        [self.navigationControllerpresentViewController:_imagePickerGanimated:YEScompletion:nil];

    } else if(type == 2){

        _imagePickerG.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

        _imagePickerG.allowsEditing = YES;

        [self.navigationControllerpresentViewController:_imagePickerGanimated:YEScompletion:nil];

    }

}

 

//取消选择图片(拍照)

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

    [picker dismissViewControllerAnimated:YEScompletion:nil];

}

 

//选择图片完成 (从相册或者拍照完成)

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *)info {

    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];//原图

//    [self UpPic:image];

    [picker dismissViewControllerAnimated:YEScompletion:nil];

}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics