我刚开始学习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
Run Code Online (Sandbox Code Playgroud)