1

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:
enter image description here

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:
enter image description here

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?

Community
  • 1
  • 1
Reinhard Männer
  • 14,022
  • 5
  • 54
  • 116

1 Answers1

1

Sometimes it helps to read the docs... They say:

IMPORTANT
The UIImagePickerController class supports portrait mode only.

So one simply must not use a UIImagePickerController in landscape mode.

Reinhard Männer
  • 14,022
  • 5
  • 54
  • 116