I'm just starting to learn iPhone app development. I am trying to extract photos from my photo album using the ALAsset class and upload the photos to my server. However, photographs taken in portrait mode are rotated 90 degrees to the left, and landscape photographs load correctly. What am I doing wrong? In NSLog, I see that the orientation is 3, but still the photo rotates 90 degrees to the left. Any help would be greatly appreciated.
Here is a snippet of my code:
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];
source
share