1 /** 2 *按照图片的层次顺序依次创建各个部分 3 */ 4 CGContextRef ctx = UIGraphicsGetCurrentContext(); 5 6 //保存上下文 7 CGContextSaveGState(ctx); 8 9 //1、先画头像周边的圆 10 CGContextAddEllipseInRect(ctx, CGRectMake(55, 55, 90, 90)); 11 12 [[UIColor greenColor] set]; 13 14 CGContextFillPath(ctx); 15 16 CGContextRestoreGState(ctx); 17 18 //2、生成裁剪头像区域 19 CGContextAddEllipseInRect(ctx, CGRectMake(60, 60, 80, 80)); 20 21 CGContextClip(ctx); 22 23 CGContextFillPath(ctx); 24 25 //3、将图片放到裁剪区域 26 UIImage *image = [UIImage imageNamed:@"2.jpg"]; 27 28 [image drawAtPoint:CGPointMake(60, 60)];
CGContextRef裁剪图片
Stella981
2021-10-11
1168 0 0
点赞
收藏
评论区
加载中...