您的位置:首页 > 产品设计 > UI/UE

iOS 将UIImage裁剪成圆形

2016-04-29 11:27 337 查看
-(UIImage*) circleImage:(UIImage*) image withParam:(CGFloat) inset {  

    UIGraphicsBeginImageContext(image.size);  

    CGContextRef context = UIGraphicsGetCurrentContext();  

    CGContextSetLineWidth(context, 2);  

    CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);  

    CGRect rect = CGRectMake(inset, inset, image.size.width - inset * 2.0f, image.size.height - inset * 2.0f);  

    CGContextAddEllipseInRect(context, rect);  

    CGContextClip(context);  

      

    [image drawInRect:rect];  

    CGContextAddEllipseInRect(context, rect);  

    CGContextStrokePath(context);  

    UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext();  

    UIGraphicsEndImageContext();  

    return newimg;  

}  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: