ios 图片剪裁(代码)
-(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];
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。