Search code examples
swiftuiimagepickercontroller

How can I make this imagePickerController able to accept edited images?


How can I make this imagePickerController able to accept edited images?

When selecting an image and adjusting it (zoom in and out) and selecting done, the image reverts back to its original state. What can I add to to my code to have the zoomed image save and show up in my image view?

The following is my code so far:

let cameraRollAction = UIAlertAction(title: "Camera Roll", style: .default) { (action) in
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary) {
        let picker = UIImagePickerController()
        picker.delegate = self
        picker.allowsEditing = true
        picker.mediaTypes = [kUTTypeImage as String]
        picker.sourceType = UIImagePickerControllerSourceType.photoLibrary
        self.present(picker, animated: true, completion: nil)
        self.newPic = false
    }

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    let mediaType = info[UIImagePickerControllerMediaType] as! NSString
    if mediaType.isEqual(to: kUTTypeImage as String) {
        let selectedImage = info[UIImagePickerControllerOriginalImage] as! UIImage
        profileImageView.image = selectedImage
        if newPic == true {
            UIImageWriteToSavedPhotosAlbum(selectedImage, self, #selector(imageError), nil)
        }
    }
    self.dismiss(animated: true, completion: nil)
}

Solution

  • Instead of

    UIImagePickerControllerOriginalImage
    

    use

    UIImagePickerControllerEditedImage