Reputation: 43
I get a picture from the photo library and call it image using this code:
@IBAction func importImage(_ sender: AnyObject) {
let image = UIImagePickerController()
image.delegate = self
image.sourceType = UIImagePickerControllerSourceType.photoLibrary
image.allowsEditing = false
self.present(image, animated: true) { }
}
and this code:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
myImageView.image = image
dismiss(animated: true, completion: nil)
SubmitBtnOutlet.isHidden = false;
Gurpcontroller.person = "yours";
Gurpcontroller.collecterthing = "Coin";
PictureViewController.imageuniversal = myImageView
} else {
//Error message
}
}
I want to see if image is landscape or portrait. Then, if it is landscape I want to change it to portrait.
Upvotes: 2
Views: 16623
Reputation: 3802
You can get the orientation by using image.imageOrientation
.
In order to change the orientation, the quickest solution would be to create a new UIImage from the actual image as follows:
let newImage = UIImage(cgImage: image.cgImage!, scale: image.scale, orientation: .up)
Upvotes: 15