Core Graphics 学习笔记 之 Image Drawing(二)
来源:互联网 发布:json.parse 源码 编辑:程序博客网 时间:2024/06/08 07:05
1.绘制箭头的三种方式
// Drawing code// CGContextRef con = UIGraphicsGetCurrentContext();// //draw a black(by default) vertical line,the shaft of the arrow 箭杆// CGContextMoveToPoint(con, 100, 100);// CGContextAddLineToPoint(con, 100, 19);// CGContextSetLineWidth(con, 20);// CGContextStrokePath(con);// //draw a red triangle,the point of the arrow// CGContextSetFillColorWithColor(con, [[UIColor redColor] CGColor]);// CGContextMoveToPoint(con, 80, 25);// CGContextAddLineToPoint(con, 100, 0);// CGContextAddLineToPoint(con, 120, 25);// CGContextFillPath(con);// //snip a triangle out of the shaft by drawing in clear blend mode// CGContextMoveToPoint(con, 90, 100);// CGContextMoveToPoint(con, 100, 90);// CGContextMoveToPoint(con, 110, 100);// CGContextSetBlendMode(con, kCGBlendModeClear);// CGContextSetAlpha(con, 1.0);// CGContextFillPath(con); //当需要获取CGPath时,可以使用UIBezierPath// UIBezierPath *p = [UIBezierPath bezierPath];// // [p moveToPoint:CGPointMake(100, 100)];// [p addLineToPoint:CGPointMake(100, 19)];// [p setLineWidth:20];// [p stroke];// [[UIColor redColor] set];// [p removeAllPoints];// [p moveToPoint:CGPointMake(80, 25)];// [p addLineToPoint:CGPointMake(100, 0)];// [p addLineToPoint:CGPointMake(120, 25)];// [p fill];// // [p removeAllPoints];// [p moveToPoint:CGPointMake(90, 101)];// [p addLineToPoint:CGPointMake(100, 90)];// [p addLineToPoint:CGPointMake(110, 101)];// [p fillWithBlendMode:kCGBlendModeClear alpha:1.0]; //Clipping CGContextRef con = UIGraphicsGetCurrentContext(); //punch triangular hole in context clipping region CGContextMoveToPoint(con, 90, 100); CGContextAddLineToPoint(con, 100, 90); CGContextAddLineToPoint(con, 110, 100); CGContextClosePath(con); CGContextAddRect(con, CGContextGetClipBoundingBox(con)); CGContextEOClip(con); //draw the vertical line CGContextMoveToPoint(con, 100, 100); CGContextAddLineToPoint(con, 100, 19); CGContextSetLineWidth(con, 20); CGContextStrokePath(con); //draw the red triangle.the point of the arrow CGContextSetFillColorWithColor(con, [[UIColor redColor] CGColor]); CGContextMoveToPoint(con, 80, 25); CGContextAddLineToPoint(con, 100, 0); CGContextAddLineToPoint(con, 120, 25); CGContextFillPath(con);效果:
CGContextRef con = UIGraphicsGetCurrentContext(); [[self arrowImage] drawAtPoint:CGPointMake(0, 0)]; for (int i=0; i<3; i++) { CGContextTranslateCTM(con, 20, 100); CGContextRotateCTM(con, 30*M_PI/180); CGContextTranslateCTM(con, -20, -100); [[self arrowImage] drawAtPoint:CGPointMake(0, 0)]; }//}-(UIImage *)arrowImage{ UIGraphicsBeginImageContextWithOptions(CGSizeMake(40, 100), NO, 0.0); CGContextRef con = UIGraphicsGetCurrentContext(); //punch triangular hole in context clipping region CGContextMoveToPoint(con, 10, 100); CGContextAddLineToPoint(con, 20, 90); CGContextAddLineToPoint(con, 30, 100); CGContextClosePath(con); CGContextAddRect(con, CGContextGetClipBoundingBox(con)); CGContextEOClip(con); //draw the vertical line CGContextMoveToPoint(con, 20, 100); CGContextAddLineToPoint(con, 20, 19); CGContextSetLineWidth(con, 20); CGContextStrokePath(con); //draw the red triangle.the point of the arrow CGContextSetFillColorWithColor(con, [[UIColor redColor] CGColor]); CGContextMoveToPoint(con, 0, 25); CGContextAddLineToPoint(con, 20, 0); CGContextAddLineToPoint(con, 40, 25); CGContextFillPath(con); UIImage *im = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return im;}
当我不是绘制在(0,0)时就有问题,好像是由坐标系统改变导致的
CGContextRef con = UIGraphicsGetCurrentContext(); [[self arrowImage] drawAtPoint:CGPointMake(150, 200)]; for (int i=0; i<12; i++) { CGContextTranslateCTM(con, 20, 100); CGContextRotateCTM(con, 30*M_PI/180); CGContextTranslateCTM(con, -20, -100); [[self arrowImage] drawAtPoint:CGPointMake(150, 200)]; }
尚未找到原因,有知道的童鞋,欢迎告知,一起交流
0 0
- Core Graphics 学习笔记 之 Image Drawing(二)
- Core Graphics 学习笔记 之 Image Drawing(一)
- 开发笔记6-Graphics学习-Drawing Lines、Drawing Rectangles
- iOS 图形图像处理 二 :Core Graphics 、Core Image and GPUImage
- Core Graphics 框架学习笔记
- 媒体层图形技术之Core Graphics 框架 学习笔记
- UIKit Graphics System---Graphics and drawing in iOS 学习笔记1
- Core Graphics 框架学习笔记,以及demo
- QT之GUI学习笔记(二十四)---Graphics View Framework
- iOS7 使用Core Graphics 和 Core Image
- Core Graphics笔记
- UIKit Graphics System--Drawing Shapes Using Bezier Paths学习笔记2
- 【IOS学习】Core Graphics 框架学习笔记,以及demo
- 【IOS学习】Core Graphics 框架学习笔记,以及demo
- 【IOS学习】Core Graphics 框架学习笔记,以及demo
- 学习笔记——使用Core Graphics绘图
- Intermediate Core Graphics(Swift)二
- Core Graphics框架学习之在图片上绘制文字
- Tomcat6 配置cgi openlayers跨域访问
- 无法定位程序输入点RegSetKeyValueA 于动态链接库 ADVAPI32.dll上 解决方案
- 用 SQL 语句还原数据库(with move 选项用法)
- 软件知识分类法
- jsp概述
- Core Graphics 学习笔记 之 Image Drawing(二)
- UESTC889&&uvalive6623 Battle for Silver(dfs)
- Linux下无需输入密码自动登陆ssh服务器方法
- 中文截取无乱码
- javascript 学习笔记(0)
- 单例模式
- 2014 年 Android 碎片化报告
- UIControlEventTouch的使用
- ThinkPHP中语言设置