美文网首页
Quartz2d--图片裁剪

Quartz2d--图片裁剪

作者: i诺离 | 来源:发表于2017-11-17 09:59 被阅读9次
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    //1.加载图片
    UIImage *image = [UIImage imageNamed:@"阿狸头像"];
    //2.生成一个跟图片相同大小图片上下文
    UIGraphicsBeginImageContextWithOptions(image.size, NO, 0);
    //3.在上下文添加一个圆形裁剪区域
    UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
    
    //把路径设置成裁剪区域
    [path addClip];

    //4.把图片绘制图片上下文.
    [image drawAtPoint:CGPointZero];
    
    //5.生成一张图片
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    //6.关闭图片上下文.
    UIGraphicsEndImageContext();
   
    self.imageV.image = newImage;    
}

相关文章

网友评论

      本文标题:Quartz2d--图片裁剪

      本文链接:https://www.haomeiwen.com/subject/fflcbttx.html