I am just starting to learn iPhone app development. I am trying to retrieve photos from my photo album using ALAsset class and upload the photos to my server. However, the photos that were taken in the Portrait mode are rotated 90 degrees to the left while the landscape photos are properly uploaded. What am I doing wrong? In the NSLog, I do see the orientation to be 3, but still the photo is rotated to 90 degrees to the left. Any help will be greatly appreciated.
Here's the 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];
// Upload the image