-(UIImage*)imageWithBorderW:(CGFloat)borderW borderColor:(UIColor*)color image:(UIImage*)image{
//1.开启一个和原始图片一样大小的位图上下文.
CGSizesize =CGSizeMake(image.size.width+2*borderW, image.size.height+2* borderW);
UIGraphicsBeginImageContextWithOptions(size,NO,0);
//2.绘制一个大圆,填充
UIBezierPath*path = [UIBezierPathbezierPathWithOvalInRect:CGRectMake(0,0, size.width, size.height)];
[BGCOLORset];
[pathfill];
//3.添加一个裁剪区域.
path = [UIBezierPathbezierPathWithOvalInRect:CGRectMake(borderW, borderW, image.size.width, image.size.height)];
[pathaddClip];
//4.把图片绘制到裁剪区域当中.
[imagedrawAtPoint:CGPointMake(borderW, borderW)];
//5.生成一张新图片.
UIImage*clipImage =UIGraphicsGetImageFromCurrentImageContext();
//6.关闭上下文.
UIGraphicsEndImageContext();
returnclipImage;
}
然后self调用即可.效果如下图
网友评论