Path Creation and Path Painting
【Path Creation and Path Painting】
Path creation and path painting are separate tasks. First you create a path. When you want to render a path, you request Quartz to paint it. As you can see in Figure 3-1, you can choose to stroke the path, fill the path, or both stroke and fill the path. You can also use a path to constrain the drawing of other objects within the bounds of the path creating, in effect, a clipping area.
1、Point:CGContextMoveToPoint
2、Lines:CGContextAddLineToPoint、CGContextAddLines
3、Arcs:CGContextAddArc、CGContextAddArcToPoint
4、Curves:CGContextAddCurveToPoint、CGContextAddQuadCurveToPoint
To close the current subpath, your application should call CGContextClosePath. This function adds a line segment from the current point to the starting point of the subpath and closes the subpath. Lines, arcs, and curves that end at the starting point of a subpath do not actually close the subpath. You must explicitly call CGContextClosePath to close a subpath.
Some Quartz functions treat a path’s subpaths as if they were closed by your application. Those commands treat each subpath as if your application had called CGContextClosePath to close it, implicitly adding a line segment to the starting point of the subpath.
After closing a subpath, if your application makes additional calls to add lines, arcs, or curves to the path, Quartz begins a new subpath starting at the starting point of the subpath you just closed.
5、Ellipses:CGContextAddEllipseInRect
6、Rectangles:CGContextAddRect、CGContextAddRects
【Creating a Path】
A graphics context can have only a single path in use at any time. If the specified context already contains a current path when you call this function, Quartz discards the old path and any data associated with it.
The current path is not part of the graphics state. Consequently, saving and restoring the graphics state has no effect on the current path.
When you want to construct a path in a graphics context, you signal Quartz by calling the function CGContextBeginPath . Next, you set the starting point for the first shape, or subpath, in the path by calling the function CGContextMoveToPoint. After you establish the first point, you can add lines, arcs, and curves to the path, keeping in mind the following:
- Before you begin a new path, call the function CGContextBeginPath.
- Lines, arcs, and curves are drawn starting at the current point. An empty path has no current point; you must call CGContextMoveToPoint to set the starting point for the first subpath or call a convenience function that implicitly does this for you.
- When you want to close the current subpath within a path, call the function CGContextClosePath to connect a segment to the starting point of the subpath. Subsequent path calls begin a new subpath, even if you do not explicitly set a new starting point.
- When you draw arcs, Quartz draws a line between the current point and the starting point of the arc.
- Quartz routines that add ellipses and rectangles add a new closed subpath to the path.
- You must call a painting function to fill or stroke the path because creating a path does not draw the path
After you paint a path, it is flushed from the graphics context. You might not want to lose your path so easily, especially if it depicts a complex scene you want to use over and over again. For that reason, Quartz provides two data types for creating reusable paths—CGPathRef and CGMutablePathRef. You can call the function CGPathCreateMutable to create a mutable CGPath object to which you can add lines, arcs, curves, and rectangles. Quartz provides a set of CGPath functions that parallel the functions discussed in “The Building Blocks.” The path functions operate on a CGPath object instead of a graphics context. These functions are:
- CGPathCreateMutable, which replacesCGContextBeginPath
- CGPathMoveToPoint, which replaces CGContextMoveToPoint
- CGPathAddLineToPoint, which replaces CGContextAddLineToPoint
- CGPathAddCurveToPoint, which replaces CGContextAddCurveToPoint
- CGPathAddEllipseInRect, which replaces CGContextAddEllipseInRect
- CGPathAddArc, which replaces CGContextAddArc
- CGPathAddRect, which replaces CGContextAddRect
- CGPathCloseSubpath, which replaces CGContextClosePath
When you want to append the path to a graphics context, you call the function CGContextAddPath. The path stays in the graphics context until Quartz paints it. You can add the path again by calling CGContextAddPath.
You can replace the path in a graphics context with the stroked version of the path by calling the function CGContextReplacePathWithStrokedPath.
【Painting a Path】
Functions for Stroking a Path:

Filling a Path

【Clipping to a Path】
The current clipping area is created from a path that serves as a mask, allowing you to block out the part of the page that you don’t want to paint. For example, if you have a very large bitmap image and want to show only a small portion of it, you could set the clipping area to display only the portion you want to show.
When you paint, Quartz renders paint only within the clipping area. Drawing that occurs inside the closed subpaths of the clipping area is visible; drawing that occurs outside the closed subpaths of the clipping area is not.

CGContextBeginPath (context);
CGContextAddArc (context, w/, h/, ((w>h) ? h : w)/, , *PI, );
CGContextClosePath (context);
CGContextClip (context);
Path Creation and Path Painting的更多相关文章
- sys.path和os.path
sys.path和os.path1.sys.path是python搜索模块的路径集合,是个list:os.path是os的一个模块,是操作文件和目录的模块 2.sys.path和PYTHONPATH首 ...
- linux环境下安装jdk(本文示例是jdk1.6.0_export JAVA_HOME=/usr/java/jdk1.6.0_45 export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar45)
第一步:创建一个文件夹安装jdk(虽说地址一般自定义,但是为了方便查找请按照笔者建议目录 ):/usr/java 将jdk-6u45-linux-x64.bin文件放到 /usr/java 文件夹 ...
- python中os.path 与sys.path
看别人写的代码,会发现两个和路径设置有关的模块 os 和sys.我对这两个模块也不是特别了解.只是记录一下自己看到的,学到的. python 中我们会使用这两个模块和文件路径, 创建文件 之类的 操作 ...
- node模块之path——path.join和path.resolve的区别
1.path.join([...paths]) path.join() 方法使用平台特定的分隔符把全部给定的 path 片段连接到一起,并规范化生成的路径. 长度为零的 path 片段会被忽略. 如果 ...
- sys.path.insert(0,"/path") 的用法
可以选择用sys.path.insert(0,‘/path’),这样新添加的目录会优先于其他目录被import检查
- path.join()与path.resolve()区别
1.path.resolve([...paths]) path.resolve() 方法会把一个路径或路径片段的序列解析为一个绝对路径. 给定的路径的序列是从右往左被处理的,后面每个 path 被依次 ...
- difference in physical path, root path, virutal path, relative virtual path, application path and aboslute path?
http://stackoverflow.com/questions/13869817/difference-in-physical-path-root-path-virutal-path-relat ...
- golang程序编译时提示“package runtime: unrecognized import path "runtime" (import path does not begin with hostname)”
在编译golang的工程时提示错误的, 提示的错误信息如下: package bytes: unrecognized import path "bytes" (import pat ...
- python脚本中selenium启动浏览器报错os.path.basename(self.path), self.start_error_message) selenium.common.excep
在python脚本中,使用selenium启动浏览器报错,原因是未安装浏览器驱动,报错内容如下: # -*- coding:utf-8 -*-from selenium import webdrive ...
随机推荐
- ajax请求返回Json字符串运用highcharts数据图表展现数据
[1].[图片] Json字符串和highcharts数据图表展现.jpg 跳至 [1] code=26754#44745" rel="nofollow"> [2] ...
- centos6.5下tomcat安装
1.安装JDK 安装:rpm –ivh jdk-7u5-linux-i586.rpm2.配置Tomcat 解压:tar -zxvf apache-tomcat-8.0.11.tar.gz 移动到/us ...
- UEditor自定义toolbar工具条
使用ueditor的同学都知道,ueditor里有很多功能,很全面,但有时候我们的编辑器不需要太多的功能,比如前台评论或者留言,就不需要这么多功能了,那我们怎么去定制自己想要的工具呢?官方给出了两个方 ...
- POJ3565带权匹配——km算法
题目:http://poj.org/problem?id=3565 神奇结论:当总边权最小时,任意两条边不相交! 转化为求二分图带权最小匹配. 可以用费用流做.但这里学一下km算法. https:// ...
- Linux环境安装jdk10
一. 下载jdk 下载方式一:直接在linux上下载 wget --no-check-certificate --no-cookies --header "Cookie: oraclelic ...
- delphi webbrowser 常用方法示例
var Form : IHTMLFormElement ; D:IHTMLDocument2 ; begin with WebBrowser1 do begin D := Document as IH ...
- ASI和TS流有什么区别
TS流是信源码流,最高码率为44.209 Mbit/s,它是经过信源编码后的压缩码流,为了使欲传输的信源信息在传输速率一定的条件下更快更多地传输,还要把数据进行压缩,也就是通过信源编码去掉信息中多余的 ...
- PHP分多步骤填写发布信息的简单方法实例代码
1.php 复制代码 代码如下: <form name=form1 id=form1 method=post action=2.php> 基本信息1:<input type=text ...
- 熟练使用Linux系统信息类命令
系统信息类命令 – dmesg命令 dmesg命令用实例名和物理名称来标识连到系统上的设备. dmesg命令显示系统诊断信息.操作系统版本号.物理内存大小以及其他信息. 系统启动时,屏幕上会显示系统C ...
- guicorn 是什么
guicorn 是什么? 在回答问题之前我们先来看看 web服务器的典型过程[1] 1. 建立链接:如果没有连接,要建立连接 2. 接收请求:对客户端发来的请求进行解析. 3. 处理请求:转发给预定义 ...