实现圆形 方形两种方式的图片裁剪:ClipImageDemo

jopen 9年前

ClipImageDemo

1.实现圆形 方形两种方式的图片裁剪,支持自定义裁剪大小,支持自定义图片缩放比例 2.基于UIImagePickerController,在UIImagePickerControllerDelegate方法中进行调用

直接上使用的关键代码 具体实现请查看YSHYClipViewController.m 文件

pragma mark - imagePickerControllerDelegate

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {    UIImage * image = info[@"UIImagePickerControllerOriginalImage"];  YSHYClipViewController * clipView = [[YSHYClipViewController alloc]initWithImage:image];  clipView.delegate = self;  clipView.clipType = clipType; //支持圆形:CIRCULARCLIP 方形裁剪:SQUARECLIP   默认:圆形裁剪  if(![textField.text isEqualToString:@""])  {      radius =textField.text.intValue;      clipView.radius = radius;   //设置 裁剪框的半径  默认120  }  //    clipView.scaleRation = 2;// 图片缩放的最大倍数 默认为3  [picker pushViewController:clipView animated:YES];    }

pragma mark - ClipViewControllerDelegate

-(void)ClipViewController:(YSHYClipViewController *)clipViewController FinishClipImage:(UIImage *)editImage {    [clipViewController dismissViewControllerAnimated:YES completion:^{      [btn setImage:editImage forState:UIControlStateNormal];  }];;    }

下面是演示效果

image

项目主页:http://www.open-open.com/lib/view/home/1449984130668