image clicked from iPhone in Portrait mode gets rotated by 90 degree

后端 未结 3 1145
逝去的感伤
逝去的感伤 2020-12-09 07:19

I am uploading an image clicked from iphone both in landscape and portrait mode. The image with landscape mode is uploaded fine but the issue is with the image uploaded with

3条回答
  •  借酒劲吻你
    2020-12-09 08:01

    Ok, a cleaner version would be :

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
        UIImage *img = [info valueForKey:UIImagePickerControllerOriginalImage];
        img = [UIImage imageWithCGImage:[img CGImage]];
    
        UIImageOrientation requiredOrientation = UIImageOrientationUp;
        switch ([[[info objectForKey:@"UIImagePickerControllerMediaMetadata"] objectForKey:@"Orientation"] intValue])
        {
            case 3:
                requiredOrientation = UIImageOrientationDown;
                 break;
            case 6:
                requiredOrientation = UIImageOrientationRight;
                break;
            case 8:
                requiredOrientation = UIImageOrientationLeft;
                break;
            default:
                break;
        }
    
        UIImage *portraitImage = [[UIImage alloc] initWithCGImage:img.CGImage scale:1.0 orientation:requiredOrientation];
    
    }
    

提交回复
热议问题