XMG Quartz2D 设置裁剪区域

1.

先获取位图上下文对象

   UIGraphicsBeginImageContextWithOptions(image.size, NO, 0);



2.

设置裁剪区域

   UIRectClip(<#CGRect rect#>) / 这个只能裁剪矩形

    UIBezierPath*path=[UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, image.size.width, image.size.height)];

    [path addClip];

3.绘制

[image drawAtPoint:

CGPointZero]

4.获取

 //4.返回当前的image

UIImage*clipImage=UIGraphicsGetImageFromCurrentImageContext();


5. 关闭路径

  UIGraphicsEndImageContext();



源码


UIImage*image=[UIImage imageNamed:@"阿狸头像"];

    

    //1.创建位图上下文

    UIGraphicsBeginImageContextWithOptions(image.size, NO, 0);

    //2.设置裁剪区域

//    UIRectClip(<#CGRect rect#>) / 这个只能裁剪矩形

    UIBezierPath*path=[UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, image.size.width, image.size.height)];

    [path addClip];

    //3.绘制

    [image drawAtPoint:CGPointZero];

    //4.返回当前的image

    UIImage*clipImage=UIGraphicsGetImageFromCurrentImageContext();

    //关闭

    UIGraphicsEndImageContext();

    







你可能感兴趣的:(XMG Quartz2D 设置裁剪区域)