传统方法
UIImage *icon = [UIImage imageNamed:@"icon.jpg"];
CGFloat w = 100;
//开始 同时开启一个上下文
UIGraphicsBeginImageContext(CGSizeMake(w, w));
//获得当前上下文
CGContextRef _context = UIGraphicsGetCurrentContext();
//画边框 ,当然你可以画出更为复杂的边框,得到不同的图片
CGContextAddArc(_context, 50, 50, 50, 0, 2*M_PI, YES);
//其实 相当于裁剪了画布
CGContextClip(_context);
//把图片画上去
[icon drawInRect:CGRectMake(0, 0, w, w) ];
//获得图片 并结束
UIImage *newIcon = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
使用贝塞尔曲线
UIImage *icon = [UIImage imageNamed:@"icon.jpg"];
CGFloat width = 100;
//开始 同时开启一个上下文
UIGraphicsBeginImageContext(CGSizeMake(width, width));
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, width, width)];
//默认裁剪当前画布
[path addClip];
//把图片画上去
[icon drawInRect:CGRectMake(0, 0, width, width) ];
//获得图片 并结束
UIImage *newIcon = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();