2D画图 & CGContextRef 常用的函数和方法
来源:互联网 发布:买汉服哪家店淘宝 编辑:程序博客网 时间:2024/05/22 17:13
// 获取上下文
CGContextRef context =UIGraphicsGetCurrentContext();
//保存当前上下文状态
CGContextSaveGState(context);
// 得到笔触
CGContextMoveToPoint(context,200,100);
//笔触点到另一个点得到一条线
CGContextAddLineToPoint(context,300,400);
// 线条转弯
CGContextAddLineToPoint(context,100,500);
// 设置笔触颜色
CGContextSetStrokeColorWithColor(context, [UIColorblackColor].CGColor);
// 设置线宽度
CGContextSetLineWidth(context,5);
// 设置join出样式
CGContextSetLineJoin(context,kCGLineJoinBevel);
//设置线末尾 lineCap
CGContextSetLineCap(context,kCGLineCapRound);
//画椭圆 其实画的是矩形的内切椭圆第一个点表示x,y坐标第二个点表示宽高
CGContextAddEllipseInRect(context,CGRectMake(50,50,50, 100));
// 画圆 同上
CGContextAddEllipseInRect(context,CGRectMake(50,200,100, 100));
CGContextAddEllipseInRect(context,CGRectMake(75,200,50, 100));
CGContextAddEllipseInRect(context,CGRectMake(50,220,100, 50));
//封闭区域的填充所有能够构成闭合区域的甚至是折线
// CGContextSetFillColorWithColor(context, [UIColor blueColor].CGColor);
//设置填充模式默认填充色是黑色
CGContextDrawPath(context,kCGPathEOFillStroke);
//显示画图信息构思后的具体样式
//填充封闭区域只要能够构成封闭的区域
CGContextFillPath(context);
// 只是描线
// CGContextStrokePath(context);
//获取先前保存的上下文状态
CGContextRestoreGState(context);
//在新的画布上重新绘图相当于构思
CGContextMoveToPoint(context,300,100);
CGContextAddLineToPoint(context,300,200);
//显示画图信息构思后的具体样式
CGContextDrawPath(context,kCGPathStroke);
-------------------------------------------------------------------------------
//通过path来画图
// 获取开始是context的状态
CGContextRestoreGState(context);
// 起始笔触点
CGPathMoveToPoint(_path,NULL, 0, 0);
CGPathAddLineToPoint(_path,NULL, 100, 100);
CGPathAddLineToPoint(_path,NULL, 0, 100);
//画椭圆 其实画的是矩形的内切椭圆第一个点表示x,y 坐标第二个点表示 宽高
CGContextAddEllipseInRect(context,CGRectMake(50,50, 50, 100));
// 画圆 同上
CGContextAddEllipseInRect(context,CGRectMake(50,200, 100, 100));
CGContextAddEllipseInRect(context,CGRectMake(75,200, 50, 100));
CGContextAddEllipseInRect(context,CGRectMake(50,220, 100, 50));
CGContextSetFillColorWithColor(context, [UIColoryellowColor].CGColor);
// 将描述好的path加入到context中
CGContextAddPath(context, _path);
// 绘制path 包括可以设置填充方式
CGContextDrawPath(context,kCGPathEOFillStroke);
- 2D画图 & CGContextRef 常用的函数和方法
- IOS CGContextRef 画图时的常用方法
- 用CGContextRef一些画图画线的方法
- 用CGContextRef一些画图画线的方法
- CGContextRef画图
- CGContextRef画图
- iOS画图的一些笔记CGContextRef
- ios画图常用的函数
- iOS Quart 2D ------------> CGContextRef
- Quart 2D画图基本方法
- IOS CGContextRef画图小结
- iOS CGContextRef画图小结
- iOS CGContextRef画图小结
- iOS CGContextRef画图小结
- iOS CGContextRef画图小结
- iOS CGContextRef画图小结
- 画图CGContextRef相关
- iOS CGContextRef画图小结
- IplImage中的widthStep大小计算及原理
- 黑马程序员_Java基础_多线程
- UIWebView的三种加载方式
- Java读书笔记01 编译和运行Java程序
- 霍纳规则(C/C++,Scheme)
- 2D画图 & CGContextRef 常用的函数和方法
- CGPonit,CGSize,CGRect
- 2010年山东省第一届ACM大学生程序设计竞赛——Clockwise
- 运动估计——块匹配算法
- [BZOJ1305]CQOI2009跳舞|最大流判定
- 刘强东哈佛演讲:解决一个问题,创业就能成功
- C++虚基类的实现机制
- UVa 10534 - Wavio Sequence (最长上升子序列LIS)
- uva 10201 Adventures in Moving - Part IV (DP)