我正在尝试使用
fullScreenImage
方法从ALAssetRepresentation
获取正确旋转的UIImage
。我有几张测试照片,以不同的设备方向拍摄; 这些照片在照片应用程序中显示正确。 fullScreenImage
的文档说明如下:
鉴于文档,我的代码如下:在iOS 5及更高版本中,此方法返回完全裁剪,旋转和调整过的图像-与用户在照片或图像选择器中看到的完全相同。
要从
CGImage
创建正确旋转的UIImage
对象,您可以使用imageWithCGImage:scale:orientation:
或initWithCGImage:scale:orientation:
,传递orientation
和scale
的值。
ALAssetRepresentation *rep = [asset defaultRepresentation];
UIImage *img = [UIImage
imageWithCGImage:[rep fullScreenImage]
scale:[rep scale]
orientation:[rep orientation]];
然而生成的UIImage
的旋转是错误的。当我将[rep orientation]
替换为UIImageOrientationUp
时,对于所有的测试照片,图像都是正确的。显然,我不确定是否应该坚持这个“解决方案”,因为它感觉像一个hack。我做错了什么?
[UIImage imageWithCGImage:[rep fullResolutionImage]]
,而你的解决方案解决了旋转问题,谢谢!(适用于iOS 8.1) - Fouad