如何立即将照片保存到相机胶卷

时间:2018-02-03 13:44:50

标签: ios swift camera

我正在开发一个可以访问相机的应用程序,它可以拍照。问题是,一旦拍摄它就不能将图像保存到相机胶卷上。我搜索了很多,似乎我应该实现一个图像视图,但我不需要我的应用程序的屏幕上的确切图像。有没有什么方法可以在不使用imageView的情况下将图像保存到相机胶卷?

这是我的imagePickerController代码

 @IBAction func openCameraButton(_ sender: AnyObject)
{
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) {
        let imagePicker = UIImagePickerController()
        imagePicker.delegate = self
        imagePicker.sourceType = UIImagePickerControllerSourceType.camera
        imagePicker.allowsEditing = false
        self.present(imagePicker, animated: true, completion: nil)
    }
}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
        imagePicked.contentMode = .scaleToFill
        imagePicked.image = pickedImage
    }
    picker.dismiss(animated: true, completion: nil)
}

1 个答案:

答案 0 :(得分:2)

这里是委托代码,您可以使用此代码进行保存尽快添加2行代码,您将删除此部分(imagePicked.image = pickedImage)因为您无法在完成之前看到图像Picker ( picker.dismiss)

忘记在info.Plist中添加2行 enter image description here

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage

    UIImageWriteToSavedPhotosAlbum(pickedImage!, nil, nil, nil);
    picker.dismiss(animated: true, completion: nil)

    imagePicked.contentMode = .scaleToFill
    imagePicked.image = pickedImage



    }

}