Quartz 2D 图形上下文栈 矩阵 裁剪
2015-06-30 02:24
232 查看
Quartz 2D 图形上下文栈 矩阵
裁剪 如:任意图片裁剪为圆形头像等
// // DJVIew.m // 图形上下文栈 // // Created by zjj on 15/6/30. // Copyright (c) 2015年 zjj. All rights reserved. // #import "DJVIew.h" @implementation DJVIew - (void)drawRect:(CGRect)rect { CGContextRef ref = UIGraphicsGetCurrentContext(); // 将ref(当前图形上下文)拷贝一份放入图形上下文栈里 CGContextSaveGState(ref); //矩阵操作 旋转 CGContextRotateCTM(ref, M_PI_4*0.3); // 矩阵操作 界面上所有图案缩放 CGContextScaleCTM(ref, 0.5, 0.5); //矩阵操作 平移 CGContextTranslateCTM(ref, 100, 100); // 设置绘图状态 [[UIColor redColor]set]; CGContextSetLineWidth(ref, 10); CGContextSetLineCap(ref, kCGLineCapRound); CGContextMoveToPoint(ref, 20, 35); CGContextAddLineToPoint(ref, 88, 195); CGContextAddEllipseInRect(ref, CGRectMake(100, 100, 100, 100));//圆 CGContextAddArc(ref,200, 200, 150, 0, M_PI*2, 0);//圆 CGContextStrokePath(ref); // // 设置绘图状态 // [[UIColor blackColor]set]; // CGContextSetLineWidth(ref, 1); // CGContextSetLineCap(ref, kCGLineCapButt); // 将栈顶上下文出栈替换当前上下文 CGContextRestoreGState(ref); CGContextAddRect(ref, CGRectMake(200, 200, 88, 88));//方 CGContextMoveToPoint(ref, 10, 50); CGContextAddLineToPoint(ref, 266, 225); CGContextStrokePath(ref); } @end
裁剪 如:任意图片裁剪为圆形头像等
相关文章推荐
- 关于 Java 性能监控您不知道的 5 件事,第 2 部分
- [.net 面向对象程序设计进阶] (3) 正则表达式 (二) 高级应用
- 感谢那些曾经帮助过我的你们,毕业的你们
- 关于 Java 常用工具您不知道的 5 件事
- 单页图片和文字一起滑动的效果
- Mybatis一对一和一对多配置
- Android.Ant.Python之批量打包(一)
- php 用for循环做,金字塔,菱形,空三角
- IDA一日速成整理笔记
- codeforces 257 div1
- Struct和Class的区别
- 09_Android中ContentProvider和Sqllite混合操作,一个项目调用另外一个项目的ContentProvider
- 09_Android中ContentProvider和Sqllite混合操作,一个项目调用另外一个项目的ContentProvider
- 多线程互斥方法
- 关于 JAR 您不知道的 5 件事
- Leecode Gas Station
- mongodb 学习笔记 06 -- mongod配置文件
- Java 运行时监控,第 3 部分: 监控应用程序生态系统的性能与可用性
- javascript 函数及作用域总结介绍
- Java 运行时监控,第 2 部分: 编译后插装和性能监控