UIImagePickerController returning incorrect image orientation

前端 未结 6 1985
北荒
北荒 2020-12-25 08:10

I\'m using UIImagePickerController to capture an image and then store it. However, when i try to rescale it, the orientation value i get out of this image is incorrect. When

6条回答
  •  不知归路
    2020-12-25 08:53

    I just started working on this issue in my own app.

    I used the UIImage category that Trevor Harmon crafted for resizing an image and fixing its orientation, UIImage+Resize.

    Then you can do something like this in -imagePickerController:didFinishPickingMediaWithInfo:

    UIImage *pickedImage = [info objectForKey:UIImagePickerControllerEditedImage];
    UIImage *resized = [pickedImage resizedImageWithContentMode:UIViewContentModeScaleAspectFit bounds:pickedImage.size interpolationQuality:kCGInterpolationHigh];
    

    This fixed the problem for me. The resized image is oriented correctly visually and the imageOrientation property reports UIImageOrientationUp.

    There are several versions of this scale/resize/crop code out there; I used Trevor's because it seems pretty clean and includes some other UIImage manipulators that I want to use later.

提交回复
热议问题