iOS 将UIImage裁剪成圆形
2016-04-29 11:27
337 查看
-(UIImage*) circleImage:(UIImage*) image withParam:(CGFloat) inset {
UIGraphicsBeginImageContext(image.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2);
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
CGRect rect = CGRectMake(inset, inset, image.size.width - inset * 2.0f, image.size.height - inset * 2.0f);
CGContextAddEllipseInRect(context, rect);
CGContextClip(context);
[image drawInRect:rect];
CGContextAddEllipseInRect(context, rect);
CGContextStrokePath(context);
UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newimg;
}
UIGraphicsBeginImageContext(image.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 2);
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
CGRect rect = CGRectMake(inset, inset, image.size.width - inset * 2.0f, image.size.height - inset * 2.0f);
CGContextAddEllipseInRect(context, rect);
CGContextClip(context);
[image drawInRect:rect];
CGContextAddEllipseInRect(context, rect);
CGContextStrokePath(context);
UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newimg;
}
相关文章推荐
- UITextField中放置UIImage 和placeholder 字体、颜色、大小、位置
- Easyui Treegrid改变默认图标的方法
- iOS开发UI篇—无限轮播(循环利用)
- ESXi安装异常:VMware ESXi requires the Excute Disable/No Exceute CPU feature to be enabled
- Could not allocate CursorWindow size due to error -12 错误解决方法
- ShortGuid--简单便捷高效不区分大小写的短唯一ID
- Permutation Sequence
- 使用NSOperation以及NSOperationQueue
- POJ 2785 4 Values whose Sum is 0(排序+二分搜索)
- UILabel UIButton 混合问题 -iOS初学
- Android TextView实现滚动跑马灯效果Marquee
- /var/spool/clientmqueue目录~清理
- Easyui 之 Treegrid 笔记
- SoapUI命令行方式运行
- burpsuite
- Kendo UI常用示例汇总(七)
- iOS 键盘样式UIKeyboardType
- iOS 各种UI控件属性设置
- Build Instructions (Windows) – The Chromium Projects
- Start Writing---StoryTeller