美文网首页
iOS 图片裁剪

iOS 图片裁剪

作者: 安静就好_ | 来源:发表于2016-08-25 11:02 被阅读19次
    #import "ViewController.h"
    
    @interface ViewController ()
    
    @property(strong,nonatomic)UIImageView *imgView;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
       
        self.imgView = [[UIImageView alloc] initWithFrame:CGRectMake(200, 200, 200, 200)];
        [self.view addSubview:self.imgView];
        //图片裁剪重新生成一张照片
        
        //加载照片
        UIImage *image = [UIImage imageNamed:@""];
        
        //设置圆形裁剪区域,正切与图片
        //创建圆形的路径
        UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, image.size.width, image.size.height)];
        //把路径设置为裁剪区域
        [path addClip];
        
        //绘制图片
        [image drawAtPoint:CGPointZero];
        
        //从上下文中获取图片
        UIImage *clipImage = UIGraphicsGetImageFromCurrentImageContext();
        
        //关闭上下文
        UIGraphicsEndImageContext();
        
        self.imgView.image = clipImage;
    
    }
    
    

    相关文章

      网友评论

          本文标题:iOS 图片裁剪

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