I'm learning how to use UIImagePickerController
and got stuck with a problem using UIImagePickerController.sourceType = .camera
.
What my app is supposed to do is:
- to allow a user to take a photo using the system view controller mentioned above
- then convert this image using
UIImage.pngData(_:)
- save this data to an appropriate struct field (doesn't matter which one, in that case)
- use data saved to the structure to make up an image and set this image as a UIButton foreground image
When i'm doing so (following App Development with Swift book's example project) image appears to be rotated 90 degrees for some reason, which I'd like to know.
I've tried to create additional UIImageView and set its image property before converting UIImage to pngData, and it appeared normally (see 2nd screenshot).
When choosing a photo from the photo library problem does not occur in any of the cases (before-after converting).
So I suppose, that pngData is somehow losing photo-orientation information? Or I've messed somewhere else, perhaps.
Here are screenshots from my app, so you can see how original taken photo looks, and how it looks in-app (above labels - UIButton, below - test UIImageView). Nevermind text :)