I have a UIImagePickerController
to take photos. I know, e.g. from UIImagePickerController doesn't fill screen that the iPhone camera has a different aspect ration that the device screen, so it is necessary to crop the camera image to get a photo without black bars.
My problem is the following:
When I take a photo in portrait mode, the preview image is cropped vertically, so that the image fills the whole preview space:
However, when I take the photo in landscape mode, the preview image is not cropped, so that a black bar appears on top of the preview image:
I have read that I can scale the preview image using the cameraViewTransform
property of the UIImagePickerController
. But I had to set this property before I take the photo, at a time when I don't know in which orientation the user will take the photo.
So if I apply a zoom transform before I take the photo, the photo will be unnecessarily cropped on all sides in portrait mode, and right in landscape mode. If I do not apply the transfer, the photo is taken right in portrait mode, but has a black top bar in landscape mode.
So what is the right way to crop the photo right (minimum cropping, but without a black bar) in both orientations?