- (void)tailoring {
UIImage *oldImage = [UIImage imageNamed:@"实现准备裁剪的图片.png"];
CGFloat borderW = 2;
CGFloat imageW = oldImage.size.width + borderW * 2;
CGFloat imageH = oldImage.size.height + borderW * 2;
UIGraphicsBeginImageContextWithOptions(CGSizeMake(imageW, imageH), NO, 0.0);
CGContextRef ctx = UIGraphicsGetCurrentContext();
// 圆环
CGFloat centerX = imageW * 0.5;
CGFloat centerY = imageH * 0.5;
CGContextAddArc(ctx, centerX, centerY, centerX, 0, M_PI * 2, 0);
[[UIColor whiteColor] set];
CGContextFillPath(ctx);
// 裁剪
CGFloat radius = oldImage.size.width * 0.5;
CGContextAddArc(ctx, centerX, centerY, radius, 0, M_PI * 2, 0);
CGContextClip(ctx);
// 画图
[oldImage drawInRect:CGRectMake(borderW, borderW, oldImage.size.width, oldImage.size.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *data = UIImagePNGRepresentation(newImage);
[data writeToFile:@"路径/图片名.png" atomically:YES];
}