-(void)viewDidLoad
{
UIImage *oldImage = [UIImage imageNamed:@"new"];
UIImage *oldImage = [UIImage imageNamed:@"new"];
CGFloat centerX = oldImage.size.width/2;
CGFloat centerY = oldImage.size.height/2;
CGFloat radius = 30;
//1.创建图形上下文
UIGraphicsBeginImageContextWithOptions(oldImage.size, NO, 0.0);
//2.获取图形上下文
CGContextRef ref =UIGraphicsGetCurrentContext();
//3.画一个圆
CGContextAddArc(ref, centerX, centerY, radius,0, M_PI *2, 0);
//4.剪切图片
CGContextClip(ref);
//5.获取当前的图片
UIImage *newImage = UIGraphicsGetImageFromCurretImageContext();
//6.结束图形上下文
UIGraphicsEndImageContext();
//7.获取数据
NSData *data = UIImagePNGRepresentation(newImge);
[data writeToFile:@"/Users/apple/DeskTop/new1.png" atomically:YES];
}
时间: 2024-10-24 04:12:40