2016-1-9 Quartz框架的学习,剪裁图片并设置边框
2024-09-21 18:46:32
#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]; }
最新文章
- vs2013 git 使用总结
- 弹窗样式 idialog,purebox,artdialog4.1.2,jquery.alert.v1.2
- github 离线版本下载
- C#: 获取执行程序所在路径和启动资源管理器
- java 中的Exception RuntimeException 区别
- [改善Java代码]集合中的元素必须做到compareTo和equals同步
- 算法 fill
- Firefly官方教程之DBentrust使用文档
- 服务器之间免密码ssh登陆
- [Cycle.js] Making our toy DOM Driver more flexible
- Could not open a connection to your authentication agent
- C++ 库研究笔记——通过inline避免hpp 的mutiple definition 错误
- git常用方法整理
- 使用DDOS deflate抵御少量DDOS攻击
- Perl 杂记
- 【Shell】总结&#183;linux shell脚本攻略
- test20190324 树
- Spring Boot 2 实践记录之 MyBatis 集成的启动时警告信息问题
- 【文文殿下】浅析scanf源码
- C语言 &#183; 矩阵相乘 &#183; 算法提高
热门文章
- 能源项目xml文件 -- app-datasource.xml
- CentOS 6.x启动时网卡eth0未激活
- hdu-----(1150)Machine Schedule(最小覆盖点)
- Sudoku Solver [LeetCode]
- Trapping Rain Water [LeetCode]
- Word Search [LeetCode]
- 《JavaScript权威指南》读书笔记(二)
- Matlab boxplot for Multiple Groups(多组数据的箱线图)
- PDF 补丁丁 0.4.1.728 测试版发布
- php 5.5.1 编译安装过程