iOS UIImagePickerController result image orientation after upload

后端 未结 20 1979
长发绾君心
长发绾君心 2020-11-22 00:44

I am testing my iPhone application on an iOS 3.1.3 iPhone. I am selecting/capturing an image using a UIImagePickerController:

UIImagePickerCont         


        
20条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 01:05

    I figured out a much simpler one:

    - (UIImage *)normalizedImage {
        if (self.imageOrientation == UIImageOrientationUp) return self; 
    
        UIGraphicsBeginImageContextWithOptions(self.size, NO, self.scale);
        [self drawInRect:(CGRect){0, 0, self.size}];
        UIImage *normalizedImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return normalizedImage;
    }
    

    BTW: @Anomie's code does not take scale into account, so will not work for 2x images.

提交回复
热议问题