iOS 剪切圆形图片

使用Quartz2D来绘制图形

+(UIImage*) circleImage:(UIImage*) image withParam:(CGFloat) inset {

UIGraphicsBeginImageContext(image.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 40);
CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
CGRect rect = CGRectMake(inset, inset, image.size.width - inset * 2.0f, image.size.height - inset * 2.0f);
CGContextAddEllipseInRect(context, rect);
CGContextClip(context);

[image drawInRect:rect];
CGContextAddEllipseInRect(context, rect);
CGContextStrokePath(context);
UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newimg;

}

通过

你可能感兴趣的:(iOS 剪切圆形图片)