Quartz 2D 绘图d
2014-10-23 11:05
134 查看
Quatrz 2D基础
Quartz 2D是iPhone OS和Mac OS X环境下的二维绘图引擎。使用Quartz 2D API,你可以接触到这样一些特性:基于路径的绘图,透明度绘图,遮盖,阴影,透明层,颜色管理,放锯齿渲染,生成PDF以及PDF元数据相关处理。Quartz 2D还可以借助硬件的力量进行图像处理。
数据类型&API
typedef struct CGContext *CGContextRef; CGContextRef一种迷糊数据类型用于描述Quartz 2D绘制图形的绘制环境 CGContextSetLineWidth(context,10); 在绘制环境里设置绘图时线的宽度,单位是:像素 CGContextSetStrokeColorWithColor(context,[UIColor redColor].CGColor); 在绘图环境里设置绘图是画笔的颜色 CGContextMoveToPoint(context,30,30); 在绘制环境里,移动画笔到初始位置 CGContextAddLineToPoint(context,200,200); 在绘图环境里,绘制直线的终点 CGContextAddRect(context,rect); 在绘图环境里绘制矩形 CGContextStrokePath(context); 开始绘制图形
划线
矩形
- (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context,10); CGContextSetStrokeColorWithColor(context,[UIColor redColor].CGColor); CGContextSetFillColorWithColor(context, [UIColor orangeColor].CGColor); CGRect rt = CGRectMake(50,60,220,60); CGContextAddRect(context,rt); CGContextDrawPath(context,kCGPathEOFill); }
矩形中间涂色
- (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context,2); CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); CGRect rectangle = CGRectMake(60,170,200,80); CGContextAddRect(context,rectangle); CGContextStrokePath(context); CGContextSetFillColorWithColor(context, [UIColor redColor],CGColor); CGContextFillRect(context,rectangle); }
椭圆
- (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context,10); CGContextSetStrokeColorWithColor(context,[UIColor redColor].CGColor); CGContextSetFillColorWithColor(context, [UIColor orangeColor].CGColor); CGRect rt = CGRectMake(50,60,220,60); CGContextAddEllipseInRect(context, rt); CGContextDrawPath(context,kCGPathEOFill); }
图像
- (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context,10); CGContextSetStrokeColorWithColor(context,[UIColor redColor].CGColor); CGContextSetFillColorWithColor(context, [UIColor orangeColor].CGColor); CGRect rt = CGRectMake(50,60,220,300); [_drawImage drawInRect:rt]; }
菱形
- (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context,2); CGContextSetStrokeColorWithColor(context,[UIColor blueColor].CGColor); CGContextMoveToPoint(context,100,100); CGContextAddLineToPoint(context,150,150); CGContextAddLineToPoint(context,100,200); CGContextAddLineToPoint(context,50,150); CGContextAddLineToPoint(context,100,100); CGContextStrokePath(context); }
菱形中间填充颜色
- (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextMoveToPoint(Context,100,100); CGContextAddLineToPoint(context,150,150); CGContextAddLineToPoint(context,100,200); CGContextAddLineToPoint(context,50,150); CGContextAddLineToPoint(context,100,100); CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor); CGContextFillPath(context); }
矩形边框+内部涂色
- (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context, 2.0); CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); CGRect rectangle = CGRectMake(60,170,200,80); CGContextAddRect(context, rectangle); CGContextStrokePath(context); CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor); CGContextFillRect(context, rectangle); }
曲线
- (void)drawRect:(CGrect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context, 2.0); CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); CGContextMoveToPoint(context, 100,100); CGContextAddArcToPoint(context,100,200, 300,200, 100); CGContextStrokePath(context); } -(void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context, 2.0); CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); CGContextMoveToPoint(context, 10,10); CGContextAddCurveToPoint(context,0,50,300,250,300,400); CGContextStrokePath(context); } - (void)drawRect:(CGrect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context, 2.0); CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); CGContextMoveToPoint(context,10,200); CGCOntextAddQuadCurveToPoint(context,150,10,300,200); CGContextStrokePath(context); } - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context, 5.0); CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); CGFloat dashArray[] = {2,6,4,2}; CGContextSetLineDash(context,3,dashArray,4); CGContextMoveToPoint(context,10,200); CGContextAddQuadCurveToPoint(context,150,10,300,200); CGContextStrokePath(context); }
相关文章推荐
- iOS 2D绘图详解(Quartz 2D)之路径(点,直线,虚线,曲线,圆弧,椭圆,矩形)
- Quartz 2d绘图
- iOS:quartz2D绘图小项目(涂鸦画板)
- 【IOS 开发学习总结-OC-64】Quartz 2D绘图(4-1)——Quartz 2D绘图基础+点线模式
- iOS开发中Quartz2D绘图路径的使用以及条纹效果的实现
- iOS绘图_Quartz 2D基础
- iOS-绘图(Quartz2D)的简单使用(原创)
- iOS Quartz2D使用(绘图路径)
- Quartz 2D简单的绘图
- IOS中的绘图Quartz2D
- iOS开发UI篇—Quartz2D使用(绘图路径
- Quartz2D绘图引擎
- 学习IOS开发UI篇--Quartz2D基本绘图
- iOS开发UI篇—Quartz2D使用(绘图路径)
- iOS学习 - Quartz2D绘图学习
- iOS绘图——Quartz 2D使用方法
- iOS 2D绘图详解(Quartz 2D)之概述
- 【IOS 开发学习总结-OC-65】Quartz 2D绘图(4-2)——绘制文本+设置阴影+使用路径
- iOS 2D绘图详解(Quartz 2D)之阴影和渐变(Shadow,Gradient)
- ios (Quartz 2D绘图)各种绘图方式及相机的使用