【发布时间】:2012-06-08 10:31:30
【问题描述】:
我正在尝试使用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。我做错了什么?
【问题讨论】:
标签: objective-c ios alassetslibrary alasset