iOS UIImage 圆形图片剪切方案
2018-07-20 来源:open-open
@interface UIImage (Resize) //按形状切割图像 - (UIImage*)cutImageWithRadius:(int)radius; @end
//图片剪切
- (UIImage*)cutImageWithRadius:(int)radius
{
UIGraphicsBeginImageContext(self.size);
CGContextRef gc = UIGraphicsGetCurrentContext();
float x1 = 0.;
float y1 = 0.;
float x2 = x1+self.size.width;
float y2 = y1;
float x3 = x2;
float y3 = y1+self.size.height;
float x4 = x1;
float y4 = y3;
radius = radius*2;
CGContextMoveToPoint(gc, x1, y1+radius);
CGContextAddArcToPoint(gc, x1, y1, x1+radius, y1, radius);
CGContextAddArcToPoint(gc, x2, y2, x2, y2+radius, radius);
CGContextAddArcToPoint(gc, x3, y3, x3-radius, y3, radius);
CGContextAddArcToPoint(gc, x4, y4, x4, y4-radius, radius);
CGContextClosePath(gc);
CGContextClip(gc);
CGContextTranslateCTM(gc, 0, self.size.height);
CGContextScaleCTM(gc, 1, -1);
CGContextDrawImage(gc, CGRectMake(0, 0, self.size.width, self.size.height), self.CGImage);
UIImage *newimage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newimage;
}
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:Android简单加密网络数据
下一篇:ios实战-弹幕的实现
最新资讯
热门推荐