/**
     *按照图片的层次顺序依次创建各个部分
     */
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
    //保存上下文
    CGContextSaveGState(ctx);
    //1、先画头像周边的圆
    CGContextAddEllipseInRect(ctx, CGRectMake(55, 55, 90, 90));
    
    [[UIColor greenColor] set];
    
    CGContextFillPath(ctx);
    
    CGContextRestoreGState(ctx);
    //2、生成裁剪头像区域
    CGContextAddEllipseInRect(ctx, CGRectMake(60, 60, 80, 80));
    
    CGContextClip(ctx);
    
    CGContextFillPath(ctx);
    
    //3、将图片放到裁剪区域
    UIImage *image = [UIImage imageNamed:@"2.jpg"];
    
    [image drawAtPoint:CGPointMake(60, 60)];
CGContextRef裁剪图片
点赞
收藏
 
  
  
  
 
 
  
 
 
 