#import "ViewController.h"
@interface ViewController ()
@property(strong,nonatomic)UIImageView *imgView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.imgView = [[UIImageView alloc] initWithFrame:CGRectMake(200, 200, 200, 200)];
[self.view addSubview:self.imgView];
//图片裁剪重新生成一张照片
//加载照片
UIImage *image = [UIImage imageNamed:@""];
//设置圆形裁剪区域,正切与图片
//创建圆形的路径
UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, image.size.width, image.size.height)];
//把路径设置为裁剪区域
[path addClip];
//绘制图片
[image drawAtPoint:CGPointZero];
//从上下文中获取图片
UIImage *clipImage = UIGraphicsGetImageFromCurrentImageContext();
//关闭上下文
UIGraphicsEndImageContext();
self.imgView.image = clipImage;
}
网友评论