裁剪图像不适用于UIImagePickerController setAllowsEditing:YES

时间:2014-11-15 00:17:48

标签: xcode uiimagepickercontroller

我正在使用UIImagePickerController来允许用户选择一张图片并将其作为个人资料图片。问题是" setAllowsEditing:YES;"似乎不起作用。裁剪系统出现了问题,但当你裁剪并按下时,选择"图像显示未剪切。我在这里环顾四周,但我似乎无法找到一个好的答案。有什么想法吗?

以下是代码:

@implementation ViewController

- (IBAction)chooseImage:(id)sender {

self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.delegate = self;
[self.imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:self.imagePicker animated:YES completion:nil];
[self.imagePicker setAllowsEditing:YES];

}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

self.chosenImage = info [UIImagePickerControllerOriginalImage];
[self.avatar setImage:self.chosenImage];
[self dismissViewControllerAnimated:YES completion:nil];

}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

[self dismissViewControllerAnimated:YES completion:nil];

}

2 个答案:

答案 0 :(得分:1)

因为您正在获取未编辑的原始图像。您需要捕获已编辑的图像。

Edited Image (use this)
 self.chosenImage = info [UIImagePickerControllerEditedImage];

Orginal Image (not this)
self.chosenImage = info [UIImagePickerControllerOriginalImage];

答案 1 :(得分:1)

使用UIImagePickerControllerEditedImage代替UIImagePickerControllerOriginalImage