回答

-4

不,UIImagePickerController不能明確地做到這一點。

如果你想根據圖像的內容來確定。這是一個難題。如何在不理解圖片內容的情況下確定圖片的方向?

我可以建議你一個技巧,你檢查返回的圖像的寬度和長度,看看它是縱向還是橫向。爲了旋轉圖像,外面有一些庫和代碼,但我沒有嘗試太多。你可以看看this blog

+0

感謝您的鏈接。我如何獲得圖像的高度和寬度? – Bryan 2010-09-16 17:23:09

+0

閱讀完鏈接後,我可能不需要定位,因爲鏈接中提供的調整大小方法將保留定位信息,並且UIImageView可以自動補償定位。 – Bryan 2010-09-16 17:26:06

+1

您可以使用exif元數據確定方向 – 2012-01-12 11:10:07

14

Vodkhang的答案部分不正確 - 現代相機在拍照時會對圖像進行明確的定位。這在現在已經有5年多了。

我以前使用的代碼在這個答案做旋轉通過閱讀「方向」信息從圖片直接:

UIImagePickerController camera preview is portrait in landscape app

+1

謝謝!這應該是正確的答案:) – 2012-01-12 11:08:25

2
// Use this UIImagePickerController's delegate method 
    - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info { 
     // Getting image user just has shoot 
     UIImage* image = [info objectForKey:UIImagePickerControllerOriginalImage]; 

     // Fixing to stick with only one orientation (UIImageOrientationUp in this case) 
     switch (image.imageOrientation) { 
      case UIImageOrientationDown: 
      case UIImageOrientationDownMirrored: 
      case UIImageOrientationLeft: 
      case UIImageOrientationLeftMirrored: 
      case UIImageOrientationRight: 
      case UIImageOrientationRightMirrored: 
       image = [UIImage imageWithCGImage:image.CGImage 
                scale:image.scale 
              orientation:UIImageOrientationUp]; // change this if you need another orientation 
       break; 
      case UIImageOrientationUp: 
      case UIImageOrientationUpMirrored: 
       // The image is already in correct orientation 
       break; 
     } 

     // Do whatever you want with image (likely pass it to some UIImageView to display) 
     UIImageView *imgView = [[UIImageView alloc] initWithImage:image]; 

     // Dismiss UIImagePickerController 
     [picker dismissModalViewControllerAnimated:NO]; 
    } 

注:UIImageView讀取imageOrientation財產和相應地顯示UIImage

+0

我的應用程序是iPad,風景只,iOS 8/9。有很多關於在UIImagePickerController上啓用橫向格式的iOS 7時代問題(這對我來說是開箱即用的),但是沒有人解釋爲什麼我在** landscape右鍵時拍攝的照片顯示爲顛倒一個UIImageView,而我在**景觀中留下的**沒有。謝謝您的回答。 – 2015-10-19 10:44:22

相關問題