我从照片库中获取了一张照片,并使用以下代码将其称为图像:
@IBAction func importImage(_ sender: AnyObject) {
let image = UIImagePickerController()
image.delegate = self
image.sourceType = UIImagePickerControllerSourceType.photoLibrary
image.allowsEditing = false
self.present(image, animated: true) { }
}
和这段代码:
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
}
}
我想看看图像是横向还是纵向。然后,如果是风景,我想将其改为肖像。
答案 0 :(得分:5)
您可以使用image.imageOrientation
来获取方向。
为了改变方向,最快的解决方案是从实际图像创建一个新的UIImage,如下所示:
let newImage = UIImage(cgImage: image.cgImage!, scale: image.scale, orientation: .up)