天天看點

CGContextRef

graphics context是圖形上下文,可以将其了解為一塊畫布,我們可以在上面進行繪畫操作,繪制完成後,将畫布放到我們的view中顯示即可,view看作是一個畫框.

quartz提供了以下幾種類型的graphics

context:

bitmap graphics context

pdf graphics context

window graphics context

layer context

post graphics context

先熟悉下cgcontextref

functions by task--按接口功能分

1、managing graphics contexts--管理圖形上下文

cgcontextflush       強制所有挂起的繪圖操作在一個視窗上下文中立即被渲染到目标裝置。

cgcontextgettypeid   傳回quartz圖形上下文的類型辨別符。

cgcontextrelease     圖形上下文的引用計數-1。

cgcontextretain      圖形上下文的引用計數+1。

cgcontextsynchronize 将一個視窗的圖像上下文内容更新,即所有的繪圖操作都會在下次同步到視窗上

2、saving and restoring the current graphics state--儲存和恢複目前圖形狀态

cgcontextsavegstate 将目前圖形狀态的副本push到圖形狀态棧中;

  每個圖形上下文維護一個儲存圖形狀态的堆棧。需要注意的是,注意,目前繪圖環境的所有方面都是圖形狀态的元素。比如目前路徑的圖像狀态是不考慮的,是以當調用這

個函數的時候是不儲存的。儲存的圖像狀态如下:

  ctm (current transformation matrix)

  clip region

  image interpolation quality

  line width

  line join

  miter limit

  line cap

  line dash

  flatness

  should anti-alias

  rendering intent

  fill color space

  stroke color space

  fill color

  stroke color

  alpha value

  font

  font size

  character spacing

  text drawing mode

  shadow parameters

  the pattern phase

  the font smoothing parameter

  blend mode

cgcontextrestoregstate 将目前圖形狀态設定為最近一次儲存的狀态,即恢複狀态。

3、getting and setting graphics state parameters--擷取和設定圖形狀态參數

cgcontextgetinterpolationquality  傳回目前的圖形上下文的插值(插值(interpolation)是在不天生像素的環境下增長圖像像素大小的一種方法,在周圍像素色彩

的根蒂根基上用算術公式計算亡失像素的色彩。)品質水準。

cgcontextsetflatness              設定彎曲的路徑中的圖形上下文的準确性。

cgcontextsetinterpolationquality  設定圖形上下文的插值品質水準。

cgcontextsetlinecap               圖形環境中的畫線的端點的樣式設定。

cgcontextsetlinedash              設定圖形上下文中的虛線的模式。

cgcontextsetlinejoin              設定圖像上下文中的接接線的樣式。

cgcontextsetlinewidth             設定圖像上下文中的線的寬度。

cgcontextsetmiterlimit            設定圖像上下文中的連接配接線的斜接限制。

cgcontextsetpatternphase          設定一個上下文的段落模式。

cgcontextsetfillpattern           在指定的圖形上下文設定的填充圖案模式。

cgcontextsetrenderingintent       在目前圖形狀态設定渲染意向。

cgcontextsetshouldantialias       設定圖形上下文的抗鋸齒開啟或關閉。

cgcontextsetstrokepattern         在指定的圖形上下文設定描邊圖案。

cgcontextsetblendmode

cgcontextsetallowsantialiasing

cgcontextsetallowsfontsmoothing

cgcontextsetshouldsmoothfonts

cgcontextsetallowsfontsubpixelpositioning

cgcontextsetshouldsubpixelpositionfonts

cgcontextsetallowsfontsubpixelquantization

cgcontextsetshouldsubpixelquantizefonts

4、constructing paths--建構路徑

these functions are used to define the geometry of the current path. for more information on how paths are defined, see cgpath reference.

這些函數是用來定義路徑的幾何形狀。對于如何定義的路徑的更多資訊,請參閱cgpath參考。

cgcontextaddarc

cgcontextaddarctopoint

cgcontextaddcurvetopoint

cgcontextaddlines

cgcontextaddlinetopoint

cgcontextaddpath

cgcontextcopypath

cgcontextaddquadcurvetopoint

cgcontextaddrect

cgcontextaddrects

cgcontextbeginpath

cgcontextclosepath

cgcontextmovetopoint

cgcontextaddellipseinrect

5、painting paths--繪畫路徑

these functions are used to stroke along or fill in the current path.

這些功能是用于邊緣或填充在目前路徑。

cgcontextclearrect

cgcontextdrawpath

cgcontexteofillpath

cgcontextfillpath

cgcontextfillrect

cgcontextfillrects

cgcontextfillellipseinrect

cgcontextstrokepath

cgcontextstrokerect

cgcontextstrokerectwithwidth

cgcontextreplacepathwithstrokedpath

cgcontextstrokeellipseinrect

cgcontextstrokelinesegments

6、getting information about paths--擷取關于路徑的資訊

cgcontextispathempty            表示目前的路徑是否包含任何的子路徑。

cgcontextgetpathcurrentpoint    傳回一個非空的路徑中的目前點。

cgcontextgetpathboundingbox     傳回包含目前路徑的最小矩形。

cgcontextpathcontainspoint      檢查目前路徑中是否包含指定的點。

7、modifying clipping paths--修改剪貼路徑

cgcontextclip                 修改目前剪貼路徑,使用非零繞數規則。

cgcontexteoclip               修改目前剪貼路徑,使用奇偶規則。

cgcontextcliptorect

cgcontextcliptorects

cgcontextgetclipboundingbox

cgcontextcliptomask

8、setting color, color space, and shadow values--設定顔色,色彩空間和陰影值

cgcontextsetalpha

cgcontextsetcmykfillcolor

cgcontextsetfillcolor

cgcontextsetcmykstrokecolor

cgcontextsetfillcolorspace

cgcontextsetfillcolorwithcolor

cgcontextsetgrayfillcolor

cgcontextsetgraystrokecolor

cgcontextsetrgbfillcolor

cgcontextsetrgbstrokecolor

cgcontextsetshadow

cgcontextsetshadowwithcolor

cgcontextsetstrokecolor

cgcontextsetstrokecolorspace

cgcontextsetstrokecolorwithcolor

9、transforming user space--轉換使用者空間

these functions allow you to examine and change the current transformation matrix (ctm) in a graphics context.

這些功能允許你檢查和更改圖形上下文的目前轉換矩陣(ctm)。

cgcontextconcatctm

cgcontextgetctm

cgcontextrotatectm

cgcontextscalectm

cgcontexttranslatectm

10、using transparency layers--使用透明圖層

cgcontextbegintransparencylayer          開始一個透明層。

  直到相應的調用cgcontextendtransparencylayer,在指定範圍内的所有後續繪制操作組合到一個完全透明的背景(它被視為一個單獨的目标緩沖區從上下文)。

調用cgcontextendtransparencylayer,使用全局alpha和陰影的上下文狀态合成到上下文中。

cgcontextbegintransparencylayerwithrect  開始透明度層,它的邊界是指定的矩形,其内容是有界的。

cgcontextendtransparencylayer            結束一個透明層。

11、drawing an image to a graphics context--繪制圖像圖形上下文

cgcontextdrawtiledimage 重複繪制的圖像,擴充到提供的矩形,填補目前剪輯區域。

cgcontextdrawimage      繪制圖像到圖形上下文中。

12、drawing pdf content to a graphics context--繪制一個圖形上下文的pdf内容

cgcontextdrawpdfpage    繪制一個pdf頁面到目前的使用者空間。

13、drawing with a gradient--制圖漸變

cgcontextdrawlineargradient  繪制一個漸變填充定義的出發點和落腳點沿線變化。

cgcontextdrawradialgradient  繪制一個沿着由所提供的開始和結束的圓限定的區域變化的漸變填充。

14、drawing with a shading--制圖底紋

cgcontextdrawshading  使用指定的陰影的背景,填充剪切路徑。

15、setting up a page-based graphics context--建立一個基于頁面的圖形上下文

cgcontextbeginpage    基于頁面的圖形上下文中開始了新的一頁。

cgcontextendpage      在基于頁面的圖形上下文結束目前的頁面。

16、drawing glyphs--繪制字形

cgcontextshowglyphs             在目前文本位置顯示一個數組的字形。

cgcontextshowglyphsatpoint      在指定的位置顯示一個數組的字形。

cgcontextshowglyphswithadvances 繪制具有不同的偏移量的一個數組字形。

cgcontextshowglyphsatpositions  在所提供的位置繪制字形。

17、drawing text--繪制文本

cgcontextgettextmatrix        傳回目前文本矩陣。

cgcontextgettextposition      傳回在繪制文本的位置。

cgcontextselectfont           設定在一個圖形上下文的字型和字型大小。

cgcontextsetcharacterspacing  設定目前字元間距。

cgcontextsetfont              設定上下文的字型。

cgcontextsetfontsize          設定上下文的字型大小。

cgcontextsettextdrawingmode   設定目前文本的繪圖模式。

cgcontextsettextmatrix        設定目前文本矩陣。

cgcontextsettextposition      設定要繪制文本的位置。

cgcontextshowtext             在目前文本位置,由目前的文本矩陣指定的點顯示一個字元數組。

cgcontextshowtextatpoint      在指定的位置顯示一個字元串。

18、converting between device space and user space--裝置空間和使用者空間之間的轉換

cgcontextgetuserspacetodevicespacetransform

cgcontextconvertpointtodevicespace

cgcontextconvertpointtouserspace

cgcontextconvertsizetodevicespace

cgcontextconvertsizetouserspace

cgcontextconvertrecttodevicespace

cgcontextconvertrecttouserspace

繼續閱讀