拍摄照片并将其保存到相机胶卷

时间:2014-07-14 20:48:29

标签: ios objective-c uiimage uiimagepickercontroller

我遇到了一个问题,我只想要一个简单的解决方案来拍照,然后将其保存在我的应用中。但到目前为止,我所能做的就是将照片加载到UIImageView中,但不会保存在相机胶卷中。

- (IBAction)takePhoto:(UIButton *)sender 
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;

    [self presentViewController:picker animated:YES completion:NULL];
}  

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{
    UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
    self.imageView.image = chosenImage;

    [picker dismissViewControllerAnimated:YES completion:NULL];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 
{
    [picker dismissViewControllerAnimated:YES completion:NULL];
}

对此有任何帮助将不胜感激。相信我,我真的需要它。

2 个答案:

答案 0 :(得分:10)

你会想要这样做:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *chosenImage = info[UIImagePickerControllerEditedImage];

    self.imageView.image = chosenImage;

    UIImageWriteToSavedPhotosAlbum(chosenImage, nil, nil, nil);

    [picker dismissViewControllerAnimated:YES completion:NULL];
}

答案 1 :(得分:0)

快捷键4

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

    if(info[UIImagePickerControllerMediaType] as! String == "public.image"){

        guard let curImage:UIImage = info[UIImagePickerControllerOriginalImage] as? UIImage else{

        return

        }

        UIImageWriteToSavedPhotosAlbum(curImage, nil, nil, nil) 
    }
}