iOS图片的裁剪
- (void)tailoring {
UIImage *oldImage = [UIImage imageNamed:@"实现准备裁剪的图片.png"];
CGFloat borderW = 2;
CGFloat imageW = oldImage.size.width + borderW * 2;
CGFloat imageH = oldImage.size.height + borderW * 2;
UIGraphicsBeginImageContextWithOptions(CGSizeMake(imageW, imageH), NO, 0.0);
CGContextRef ctx = UIGraphicsGetCurrentContext();
// 圆环
CGFloat centerX = imageW * 0.5;
CGFloat centerY = imageH * 0.5;
CGContextAddArc(ctx, centerX, centerY, centerX, 0, M_PI * 2, 0);
[[UIColor whiteColor] set];
CGContextFillPath(ctx);
// 裁剪
CGFloat radius = oldImage.size.width * 0.5;
CGContextAddArc(ctx, centerX, centerY, radius, 0, M_PI * 2, 0);
CGContextClip(ctx);
// 画图
[oldImage drawInRect:CGRectMake(borderW, borderW, oldImage.size.width, oldImage.size.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *data = UIImagePNGRepresentation(newImage);
[data writeToFile:@"路径/图片名.png" atomically:YES];
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。