我从照片库中获取一张照片,并使用以下代码将其称为图像:

@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
    }
}

我想看看图像是横向的还是纵向的。如果是横向的,我想改成纵向的。

最佳答案

您可以使用image.imageOrientation获得方向。
为了更改方向,最快的解决方案是根据实际图像创建新的uiimage,如下所示:

let newImage = UIImage(cgImage: image.cgImage!, scale: image.scale, orientation: .up)

10-07 19:01
查看更多