我刚刚开始学习 iPhone 应用程序开发。我正在尝试使用 ALAsset 类从我的相册中检索照片并将照片上传到我的服务器。但是,在正确上传风景照片时,以人像模式拍摄的照片会向左旋转 90 度。我究竟做错了什么?在 NSLog 中,我确实看到方向为 3,但照片仍向左旋转 90 度。任何帮助将不胜感激。
这是我的代码片段:
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
imagePath = [[documentsDirectory stringByAppendingPathComponent:@"latest_photo.jpg"] copy];
NSLog(@"imagePath = %@", imagePath);
ALAssetRepresentation *rep = [myasset defaultRepresentation];
ALAssetOrientation orientation = [rep orientation];
NSLog(@"Orientation = %d", orientation);
CGImageRef iref = [rep fullResolutionImage];
if (iref) {
UIImage *largeimage = [UIImage imageWithCGImage:iref scale:1.0 orientation:orientation];
NSData *webData = UIImageJPEGRepresentation(largeimage,0.5);
[webData writeToFile:imagePath atomically:YES];
// Upload the image