UIImagePickerController Camera Capture - default is square

You want to provide only a square capture of photos from our application. Right now, using the code below, it allows for a square crop after capture. But you want it to be exactly the same as the default square camera option. Also, we do not want to show anything but a square.

Below is the code we use.

UIImagePickerController *controller = [[UIImagePickerController alloc] init]; controller.sourceType = UIImagePickerControllerSourceTypeCamera; controller.allowsEditing = YES; controller.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto; // controller.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypeCamera]; controller.delegate = self; [self.navigationController presentViewController: controller animated: YES completion: nil]; 

Attached screen shot

  • This is our app. We are getting this

  • We want this to be so. Want it to be like this with only square option

+6
source share
2 answers

set allowEditing to YES. from dict result use UIImagePickerControllerEditedImage key

then you will get a square image.

I do not see the opportunity to choose the user, what format he wants: (

0
source

as Shubham Narang mentions, use UIImagePickerControllerEditedImage in the imagePickerController: didFinishPickingMediaWithInfo method.

 UIImage *originalImage = (UIImage *) [info objectForKey:UIImagePickerControllerEditedImage]; if(!originalImage) { originalImage = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage]; } 

This code will use the original image if the edited (cropped) image does not exist.

0
source

Source: https://habr.com/ru/post/981095/


All Articles