#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
// 获取要剪裁的图片
UIImage *image = [UIImage imageNamed:@"papa"];
// 给图片设置的rect
CGRect imageRect = CGRectMake(, , image.size.width, image.size.height);
// 开启图形上下文
UIGraphicsBeginImageContextWithOptions(image.size, NO, 0.0);
// 获取图形上下文
CGContextRef bitmapContext = UIGraphicsGetCurrentContext();
// 画圆的路径
CGContextAddEllipseInRect(bitmapContext, imageRect);
// 把圆路径之外的剪切掉
CGContextClip(bitmapContext);
// 在上下文中添加图片
[image drawInRect:imageRect];
// 给图片设置边框
//给边框设置宽度
CGContextSetLineWidth(bitmapContext, );
//给边框设置颜色
[[UIColor blueColor] set];
CGContextAddEllipseInRect(bitmapContext, imageRect);
// 画出该边框
CGContextStrokePath(bitmapContext);
// 获取这个图片
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
// 结束位图编辑
UIGraphicsEndImageContext();
// 显示图片
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(, , , )];
[self.view addSubview:imageView];
imageView.image = newImage;
// 保存图片
// 先把图片转存NSData,调用write方法
NSData *imageData = UIImagePNGRepresentation(newImage);
[imageData writeToFile:@"/Users/mac/Desktop/new.png" atomically:YES]; }

最新文章

  1. vs2013 git 使用总结
  2. 弹窗样式 idialog,purebox,artdialog4.1.2,jquery.alert.v1.2
  3. github 离线版本下载
  4. C#: 获取执行程序所在路径和启动资源管理器
  5. java 中的Exception RuntimeException 区别
  6. [改善Java代码]集合中的元素必须做到compareTo和equals同步
  7. 算法 fill
  8. Firefly官方教程之DBentrust使用文档
  9. 服务器之间免密码ssh登陆
  10. [Cycle.js] Making our toy DOM Driver more flexible
  11. Could not open a connection to your authentication agent
  12. C++ 库研究笔记——通过inline避免hpp 的mutiple definition 错误
  13. git常用方法整理
  14. 使用DDOS deflate抵御少量DDOS攻击
  15. Perl 杂记
  16. 【Shell】总结&#183;linux shell脚本攻略
  17. test20190324 树
  18. Spring Boot 2 实践记录之 MyBatis 集成的启动时警告信息问题
  19. 【文文殿下】浅析scanf源码
  20. C语言 &#183; 矩阵相乘 &#183; 算法提高

热门文章

  1. 能源项目xml文件 -- app-datasource.xml
  2. CentOS 6.x启动时网卡eth0未激活
  3. hdu-----(1150)Machine Schedule(最小覆盖点)
  4. Sudoku Solver [LeetCode]
  5. Trapping Rain Water [LeetCode]
  6. Word Search [LeetCode]
  7. 《JavaScript权威指南》读书笔记(二)
  8. Matlab boxplot for Multiple Groups(多组数据的箱线图)
  9. PDF 补丁丁 0.4.1.728 测试版发布
  10. php 5.5.1 编译安装过程