我在作物期间遇到了问题。在横向拍摄时效果很好但是当我拍摄时它不会裁剪。我希望用户也只能使用肖像。我的代码中有什么问题导致无法正常工作或者我应该添加代码吗?第一个代码用于相机启动,第二个imagepickercontroller用于裁剪。
-(IBAction)cameraButtonPressed:(id)sender
{
UIImagePickerController *pickerController = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
pickerController.delegate = self;
[self presentViewController:pickerController
animated:YES
completion:nil];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
{
UIImage *imageTaked = info[UIImagePickerControllerOriginalImage];
//You can take the metadata here => info [UIImagePickerControllerMediaMetadata];
UIImage* imageCropped;
CGFloat side = MIN(imageTaked.size.width, imageTaked.size.height);
CGFloat x = imageTaked.size.width / 320 - side / 320;
CGFloat y = imageTaked.size.height / 320 - side / 320;
CGRect cropRect = CGRectMake(x,y,side,side);
CGImageRef imageRef = CGImageCreateWithImageInRect([imageTaked CGImage], cropRect);
imageCropped = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
}
}