OC画笔CGContextRef
2015-11-26 14:02
323 查看
1.画线
CGContextRef context = UIGraphicsGetCurrentContext();//context相当于画布
CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);//设置线得颜色
CGContextMoveToPoint(context, 100, 100);//画笔的起始点
CGContextAddLineToPoint(context, 150, 150);//画笔的终点
CGContextStrokePath(context);//绘画结束
2.画圆
CGContextRef context = UIGraphicsGetCurrentContext();//context相当于画布
//CGContextAddArc(<#CGContextRef c#>, <#CGFloat x#>, <#CGFloat y#>, <#CGFloat radius#>, <#CGFloat startAngle#>, <#CGFloat endAngle#>, <#int clockwise#>)
CGContextAddArc(context, 100, 100, 50, M_PI, M_PI*3/2, 0);// x y 相当于圆心 radius半径 startAngle起始弧度 endAngle终止弧度 clockwise 0为顺时针,1为逆时针
CGContextStrokePath(context);
3.画一个有填充色的矩形
CGContextRef context = UIGraphicsGetCurrentContext();//得到画布
CGContextSetFillColorWithColor(context, [UIColor blueColor].CGColor);//设置矩形的填充色
CGContextAddRect(context, CGRectMake(100, 200, 100, 200));// x,y起始点 width 宽度 height 高度
CGContextFillPath(context);//填充矩形
CGContextStrokePath(context);//绘画结束
4.画图
UIGraphicsBeginImageContext(self.view.bounds.size); //currentView 当前的view 创建一个基于位图的图形上下文并指定大小
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];//renderInContext呈现接受者及其子范围到指定的上下文
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();//返回一个基于当前图形上下文的图片
UIGraphicsEndImageContext();//移除栈顶的基于当前位图的图形上下文
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);//然后将该图片保存到图片图
CGContextRef context = UIGraphicsGetCurrentContext();//context相当于画布
CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);//设置线得颜色
CGContextMoveToPoint(context, 100, 100);//画笔的起始点
CGContextAddLineToPoint(context, 150, 150);//画笔的终点
CGContextStrokePath(context);//绘画结束
2.画圆
CGContextRef context = UIGraphicsGetCurrentContext();//context相当于画布
//CGContextAddArc(<#CGContextRef c#>, <#CGFloat x#>, <#CGFloat y#>, <#CGFloat radius#>, <#CGFloat startAngle#>, <#CGFloat endAngle#>, <#int clockwise#>)
CGContextAddArc(context, 100, 100, 50, M_PI, M_PI*3/2, 0);// x y 相当于圆心 radius半径 startAngle起始弧度 endAngle终止弧度 clockwise 0为顺时针,1为逆时针
CGContextStrokePath(context);
3.画一个有填充色的矩形
CGContextRef context = UIGraphicsGetCurrentContext();//得到画布
CGContextSetFillColorWithColor(context, [UIColor blueColor].CGColor);//设置矩形的填充色
CGContextAddRect(context, CGRectMake(100, 200, 100, 200));// x,y起始点 width 宽度 height 高度
CGContextFillPath(context);//填充矩形
CGContextStrokePath(context);//绘画结束
4.画图
UIGraphicsBeginImageContext(self.view.bounds.size); //currentView 当前的view 创建一个基于位图的图形上下文并指定大小
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];//renderInContext呈现接受者及其子范围到指定的上下文
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();//返回一个基于当前图形上下文的图片
UIGraphicsEndImageContext();//移除栈顶的基于当前位图的图形上下文
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);//然后将该图片保存到图片图
相关文章推荐
- Json序列化对象
- emmet教程
- LeetCode(282) Peeking Iterator
- leetcode_Word Pattern
- 如何规划构建一套大型的Citrix桌面虚拟化架构 - Part4
- 软件性能测试基本概念释疑
- iostat详细使用
- Mac版Adobe Acrobat Reader修改pdf背景颜色
- Storm:最火的流式处理框架
- 【Oracle错误】:ORA-01034&ORA-27101
- 【转】 Linux中的工作队列
- Android应用开发SharedPreferences存储数据的使用方法
- 【转】spin_lock & mutex_lock的区别? .
- RPM包制作最简单样例
- linux小白
- JS生成UUID的方法实例
- Java中读取某个目录下的所有文件和文件夹
- C++11 智能指针 unique_ptr shared_ptr weak_ptr
- selenium 2 + python 窗口定位
- word多级列表