图像裁剪选项

Cropping Option For Image

我想从相册中选择图片并用相机拍摄。它的代码运行良好,但我需要 select 只有部分图像意味着裁剪图像设置我的 imageView。

-(IBAction)chooseAlbum:(id)sender
{
    imagePicker=[[UIImagePickerController alloc]init];
    imagePicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
    imagePicker.delegate=self;
    [self presentViewController:imagePicker animated:YES completion:nil];
}

-(IBAction)takePicture:(id)sender
{
    imagePicker=[[UIImagePickerController alloc]init];
    imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera;
    imagePicker.delegate = self;

    [self presentViewController:imagePicker animated:YES completion:nil];
}

-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
     profileImageView.image=[info objectForKey:UIImagePickerControllerOriginalImage];

    [self dismissViewControllerAnimated:YES completion:nil];
}

开启编辑模式

imagePicker.allowsEditing = YES;

然后在你的委托方法中使用UIImagePickerControllerEditedImage

-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info {
    profileImageView.image=[info objectForKey:UIImagePickerControllerEditedImage];
    [self dismissViewControllerAnimated:YES completion:nil];
}

但是,如果您想要更好的控制和愉悦,也可以使用以下第三方库 effect/animation。
https://github.com/myang-git/iOS-Image-Crop-View

您只需添加 属性 imagePicker。

imagePicker.allowsEditing = YES;