如何实现拍照或从ios中的图库选项中选择

时间:2016-04-18 06:11:00

标签: ios iphone

任何人都可以帮我实现功能 - >在应用程序中选择相机选项时拍摄照片或从图库选项中选择。

1 个答案:

答案 0 :(得分:12)

//用于通过相机拍摄图像

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    [self presentViewController:picker animated:YES completion:nil];

//从图库中挑选图片

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentViewController:picker animated:YES completion:nil];

//输出图像

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

    // output image
    UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
    self.profileImageView.image = chosenImage;
    [picker dismissViewControllerAnimated:YES completion:nil];

}

不要忘记添加UIImagePickerControllerDelegate和UINavigationControllerDelegate。

相关问题