如何从ALAssetRepresentation获取正确的旋转UIImage?

我正在尝试使用fullScreenImage方法从ALAssetRepresentation获取正确旋转的UIImage 。 我有几个testing照片在各种设备方向拍摄; 照片在照片应用中正确显示。 fullScreenImage的文档说:

在iOS 5和更高版本中,此方法返回完全裁剪,旋转和调整的图像 – 完全像用户在照片或图像select器中看到的一样。

要从CGImage创build一个正确旋转的UIImage对象,可以使用imageWithCGImage:scale:orientation:initWithCGImage:scale:orientation:传递orientationscale值。

鉴于文档,我的代码如下所示:

 ALAssetRepresentation *rep = [asset defaultRepresentation]; UIImage *img = [UIImage imageWithCGImage:[rep fullScreenImage] scale:[rep scale] orientation:[rep orientation]]; 

但是由此产生的UIImage的旋转是错误的。 当我用UIImageOrientationUpreplace[rep orientation]时,对于所有的testing照片,图像都是正确的。 显然,我很犹豫要坚持这个“解决scheme”,因为它感觉像一个黑客。 我究竟做错了什么?

 ALAssetRepresentation *rep = [asset defaultRepresentation]; UIImage *img = [UIImage  imageWithCGImage:[rep fullScreenImage]  scale:[rep scale]  orientation:UIImageOrientationUp]; 

在iOS 5下是正确的,fullscreenimages已经旋转(所以它总是“上”)。 在iOS 4下,行为是不同的。 请参阅ALAsset中的“ 照片”方向不正确,以获得更深入的解释。