#####裁切图片(圆头像的实现) #####1.仍是那几个步骤git
#####2.步骤详细在代码里github
- (void)viewDidLoad { [super viewDidLoad]; //加载图片 UIImage *image=[UIImage imageNamed:@"阿狸头像"]; //开启图片上下文 UIGraphicsBeginImageContextWithOptions(image.size, NO, 0); //裁切 //裁切范围 //如下两种方法均可以 UIBezierPath *path=[UIBezierPath bezierPathWithArcCenter:CGPointMake(image.size.width*0.5, image.size.height*0.5) radius:image.size.width*0.5 startAngle:0 endAngle:M_PI*2 clockwise:YES]; // UIBezierPath *path=[UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, image.size.width, image.size.height)]; [path addClip]; //[path fill]; //绘制图片 [image drawAtPoint:CGPointZero]; //从上下文中得到裁切好的图片 UIImage *image1=UIGraphicsGetImageFromCurrentImageContext(); //关闭图片上下文 UIGraphicsEndImageContext(); //显示 self.imageView.image=image1; }
#####3.效果图片.net
#####4.源代码的地址code