gpt4 book ai didi

ios - Swift - 从 UIImagePickerController Camera 中选取时,UIImage 旋转了 90 度

转载 作者:行者123 更新时间:2023-11-28 08:42:24 27 4
gpt4 key购买 nike

我正在使用 UIImagePickerController 从相机和库中选取图像。当我从图书馆获取图片时,图片正常。但是,当我从相机中获取图片时,它会向右旋转 90 度。我的应用程序只能在纵向模式下运行。这是我获取图像的代码

    @IBAction func camPhoto(sender: AnyObject) {

let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.Camera
imagePicker.allowsEditing = false

self.presentViewController(imagePicker, animated: true, completion: nil)

}

@IBAction func importPhoto(sender: AnyObject) {

let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
imagePicker.allowsEditing = false

self.presentViewController(imagePicker, animated: true, completion: nil)

}

我的函数 importPhoto 工作正常,但另一个没有。

    func imagePickerController(picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let selectedPhoto = info[UIImagePickerControllerOriginalImage] as! UIImage

img.image = selectedPhoto
dismissViewControllerAnimated(true, completion: {

self.convBtn.hidden = false

})
}

有什么想法吗?

最佳答案

你可以试试:

func imagePickerController(picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let selectedPhoto = info[UIImagePickerControllerOriginalImage] as! UIImage
**selectedPhoto.withHorizontallyFlippedOrientation()**
img.image = selectedPhoto
dismissViewControllerAnimated(true, completion: {

self.convBtn.hidden = false

})
}

关于ios - Swift - 从 UIImagePickerController Camera 中选取时,UIImage 旋转了 90 度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36192117/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com