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

【代码笔记】将图片处理成圆的

时间:2016-04-06 09:45:26      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:

一,效果图。

技术分享

二,工程图。

技术分享

三,代码。

ViewController.m

技术分享
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    //初始化界面
    [self addView];
    
}
#pragma -mark -functions
//初始化界面
-(void)addView
{
    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/5357854.html

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