码迷,mamicode.com
首页 > 其他好文 > 详细

将图片转化为圆的

时间:2015-03-11 16:39:22      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

 

效果图:

技术分享

代码:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(20, 50, 100, 100)];
    imageView.image=[self changeimagetocilce:[UIImage imageNamed:@"1.png"]];
    [self.view addSubview:imageView];
    
    
}
//将图片处理成圆的
-(id)changeimagetocilce:(UIImage*)image
{
    UIImage *finalImage = nil;
    UIGraphicsBeginImageContext(image.size);
    {
        CGContextRef ctx = UIGraphicsGetCurrentContext();
        CGAffineTransform trnsfrm = CGAffineTransformConcat(CGAffineTransformIdentity, CGAffineTransformMakeScale(1.0, -1.0));
        trnsfrm = CGAffineTransformConcat(trnsfrm, CGAffineTransformMakeTranslation(0.0, image.size.height));
        CGContextConcatCTM(ctx, trnsfrm);
        CGContextBeginPath(ctx);
        CGContextAddEllipseInRect(ctx, CGRectMake(0.0, 0.0, image.size.width, image.size.height));
        CGContextClip(ctx);
        CGContextDrawImage(ctx, CGRectMake(0.0, 0.0, image.size.width, image.size.height), image.CGImage);
        finalImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    }
    
    return finalImage;
}

 

将图片转化为圆的

标签:

原文地址:http://www.cnblogs.com/yang-guang-girl/p/4330034.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!