从Filemanager加载时自动旋转的UIImage

问题描述:

当我在肖像模式中拍照时,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数据的旋转标志的

它。每个图像文件都有元数据属性。如果元数据指定了其他操作系统除Mac之外通常忽略的图像方向。拍摄的大部分图像都将其元数据属性设置为直角。所以Mac显示它是90度旋转的方式。你可以在windows操作系统中以适当的方式看到相同的图像。请检查this回答哪个显示更多细节