iOS 画图 图片圆形处理 并画圈

来源:互联网 发布:php管理软件 编辑:程序博客网 时间:2024/04/30 19:57


@implementation singeImg (SCHCircelImage)

+ (UIImage *)circleImageName:(NSString *)path borderWith:(double)border colorWith:(UIColor *)color

{

   UIImage *img=[UIImageimageNamed:path];

    UIGraphicsBeginImageContext(img.size );

    

    CGContextRef ctr=UIGraphicsGetCurrentContext();

    

   double radius=img.size.height>img.size.width?(img.size.width/2):(img.size.height/2);

    

    radius/=2;

    

    

   double centerx=img.size.width/2;

   double centery=img.size.height/2;

    

    

    [colorset];

 //   CGContextSetLineWidth(ctr, border);

   CGContextAddArc(ctr, centerx, centery, radius+border,0, M_PI_2*4,YES);

    CGContextFillPath(ctr);


   CGContextAddArc(ctr, centerx, centery, radius,0, M_PI_2*4,YES);

    

    CGContextClip(ctr);

     

    [imgdrawInRect:CGRectMake(0,0, img.size.width, img.size.height)];

    

    UIImage *newImg=UIGraphicsGetImageFromCurrentImageContext();

    

    

    UIGraphicsEndImageContext();

   return newImg;

  

}

@end


0 0