2017-07-28 37 views
0

當我在肖像模式中拍照時,savedImage在設置爲UIImageView時自動旋轉。從Filemanager加載時自動旋轉的UIImage

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"ProfilePicture.png"]; 
[UIImagePNGRepresentation(image) writeToFile:filePath atomically:YES]; 

UIImage *savedImage = [UIImage imageWithData:[NSData dataWithContentsOfFile:filePath]]; 

但是當我使用UIImageJPEGRepresentation: writeToFile: atomically:方法,結果圖像沒有問題。

任何人都可以請解釋爲什麼我沒有得到正確的方向圖像,而使用UIImageJPEGRepresentation &不在UIImagePNGRepresentation

注:我試過

UIImage *imageToDisplay = 
    [UIImage imageWithCGImage:[originalImage CGImage] 
       scale:[originalImage scale] 
       orientation: UIImageOrientationUp]; 

保存imageToDisplay,但不工作,因爲在JPEG的EXIF數據的旋轉標誌的

回答

1

它。每個圖像文件都有元數據屬性。如果元數據指定了其他操作系統除Mac之外通常忽略的圖像方向。拍攝的大部分圖像都將其元數據屬性設置爲直角。所以Mac顯示它是90度旋轉的方式。你可以在windows操作系統中以適當的方式看到相同的圖像。請檢查this回答哪個顯示更多細節