下面的代码可以裁剪出圆形的图片,

1,先把不规则图片转成正方形图片

UIGraphicsBeginImageContext(newSize);
   
 [image drawInRect:CGRectMake(0,0,newSize.width,newSize.width)];

 UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();

 UIGraphicsEndImageContext();

2 ,把正方形图像绘制剪切为圆形

 UIGraphicsBeginImageContext(image.size);
 CGContextRef context = UIGraphicsGetCurrentContext();

    
 CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);
 CGContextAddEllipseInRect(context, rect);
 CGContextClip(context); //进行剪切,所有context绘制只保留能够被当前path进行fill的区域
 [image drawInRect:rect]; //绘制原图
   
    
 UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext();
 UIGraphicsEndImageContext();

 

相关文章:

  • 2022-12-23
  • 2021-11-21
  • 2021-06-30
  • 2021-05-31
  • 2021-12-17
  • 2021-04-16
  • 2022-02-07
猜你喜欢
  • 2021-12-04
  • 2021-12-24
  • 2022-12-23
  • 2021-10-01
  • 2022-12-23
  • 2022-12-23
  • 2022-01-15
相关资源
相似解决方案