美文网首页
ios将图片切圆,描边

ios将图片切圆,描边

作者: 我站在冰上 | 来源:发表于2017-12-21 11:24 被阅读58次

-(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调用即可.效果如下图

相关文章

网友评论

      本文标题:ios将图片切圆,描边

      本文链接:https://www.haomeiwen.com/subject/fagowxtx.html