图片画圆使用上下文

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;

}

你可能感兴趣的:(图片画圆使用上下文)