首页 > 移动平台 > 详细

ios 将图片变成圆形

时间:2015-02-04 12:34:05      阅读:202      评论:0      收藏:0      [点我收藏+]

#pragma mark - 将图片转换成圆形

-(UIImage*) circleImage:(UIImage*) image withParam:(CGFloat) inset {

    UIGraphicsBeginImageContext(image.size);

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetLineWidth(context, 2);

    CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].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;

}

上面代码注意 如果裁剪后没有使用 CGContextAddEllipseInRect(context, rect);
CGContextStrokePath(context); 这条代码 就会引起背景为白色时看不出来任务效果。
这里是椭圆操作

ios 将图片变成圆形

原文:http://www.cnblogs.com/zj901203/p/4271929.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!