Reputation: 435
I am using the UIImagePickerViewController
(UIImagePickerControllerSourceTypeCamera
) to take a photo in my app. However when the photo is taken in landscape, a large black bar appears on top of the image in the preview/cropping view (there's a slim black bar on the bottom as well). Like so -
Here's my code -
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
In contrast, when a landscape photo is picked from the Photo Library it is placed in the centre of the preview with even black bars on top and bottom.
Where is this coming from? How do I get rid of it?
Upvotes: 7
Views: 429
Reputation: 1
steamx's answer, but for Swift worked for me:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
let cropRect = (info[UIImagePickerController.InfoKey.cropRect] as? CGRect)!
if cropRect.origin.y < 0 {
self.selectedImage = info[.originalImage] as? UIImage
} else {
self.selectedImage = info[.editedImage] as? UIImage
}
self.dismiss(animated: true, completion: nil)
}
We check if the photo the User took was edited/cropped or not.
If not, then we use the info[.originalImage]
Upvotes: 0
Reputation: 1016
From this Link
#pragma mark UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *img = nil;
CGRect cropRect = [[info valueForKey:UIImagePickerControllerCropRect] CGRectValue];
if (cropRect.origin.y < 0) {
img = [info objectForKey:UIImagePickerControllerOriginalImage];
} else {
img = [info objectForKey:UIImagePickerControllerEditedImage];
}
}
Upvotes: 0