2017-03-09 235 views
0

我得到的是從相機拍攝的圖像。我將該圖像上傳到服務器。從服務器獲得相同的圖像後,它會旋轉90度。我搜索並嘗試了更多的代碼。但沒有奏效。請指導我。來自相機拍攝圖像的圖像旋轉問題

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { 
    if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage { 
     let image = info[UIImagePickerControllerOriginalImage] as! UIImage 
     // let imgData: NSData = NSData(data: UIImageJPEGRepresentation((image), 1.0)!) 
     uploadImageToServer(img: image) 
    } 
+0

有沒有,如果有什麼區別你採取圖片肖像或風景? –

+0

很多很多的討論,答案和與此相關的示例代碼。你嘗試過哪些代碼不起作用? – DonMag

+0

檢查答案發布在https://stackoverflow.com/a/27083555/4646572 – krlb

回答

0

解決這個問題的最簡單的方法是允許在的UIImagePickerController照片編輯:

let imagePicker = UIImagePickerController() 
imagePicker.allowsEditing = true 

而且在委託取編輯的圖像:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { 
    guard let image = info[UIImagePickerControllerEditedImage] as? UIImage else { return } 
    picker.dismiss(animated: true, completion: nil) 
} 
相關問題