For my iOS app I need a Fotoeditor. Therefore I set:
imagePicker.allowsEditing = true
Now I would like to change the size of the editable area.
Here is the editable area, but I need the size of the usable image different:
How can I change the size of this area to use a different size for the usable image area?
Here is my code for my PickerController
@IBOutlet weak var preview: UIImageView!
let imagePicker = UIImagePickerController()
@IBAction func selectImage(_ sender: Any) {
imagePicker.allowsEditing = true
imagePicker.sourceType = .photoLibrary
present(imagePicker, animated: true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
imagePicker.delegate = self
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage{
preview.contentMode = .scaleAspectFit
preview.image = pickedImage
}
dismiss(animated: true, completion: nil)
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
dismiss(animated: true, completion: nil)
}
I was trying to save the edited image from the library or the camera and I didn't find anything on the web so I try this code and it works! Swift 4.2
if let pickedImage = info[UIImagePickerController.InfoKey.editedImage] as? UIImage{
imageProfile.contentMode = .scaleAspectFit
imageProfile.image = pickedImage
}
this lines of code have to be inside the function
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]){}