图片画圆使用上下文
2021-11-18 本文已影响0人
2d4c16f407e8
https://github.com/LZY-WLY/CircleImage
- (UIImage *)circleImage {
//开启图片上下文
UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0);
//获得上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
//添加一个圆
CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
CGContextAddEllipseInRect(ctx, rect);
//剪接
CGContextClip(ctx);
//将图片画上去
[selfdrawInRect:rect];
//得到图片
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
//结束图片上下文
UIGraphicsEndImageContext();
returnimage;
}