IOS開發(fā)筆記之繪圖(CGContext小記)

0CGContextRef context = UIGraphicsGetCurrentContext(); 設(shè)置上下文

1 CGContextMoveToPoint 開始畫線

2 CGContextAddLineToPoint 畫直線

4 CGContextAddEllipseInRect 畫一橢圓

4 CGContextSetLineCap 設(shè)置線條終點(diǎn)形狀

4 CGContextSetLineDash 畫虛線

4 CGContextAddRect 畫一方框

4 CGContextStrokeRect 指定矩形

4 CGContextStrokeRectWithWidth 指定矩形線寬度

4 CGContextStrokeLineSegments 一些直線

5 CGContextAddArc 畫已曲線 前倆店為中心 中間倆店為起始弧度 最后一數(shù)據(jù)為0則順時(shí)針畫 1則逆時(shí)針

5 CGContextAddArcToPoint(context,0,0, 2, 9, 40);//先畫倆條線從point 到 弟1點(diǎn) , 從弟1點(diǎn)到弟2點(diǎn)的線切割里面的圓

6 CGContextSetShadowWithColor 設(shè)置陰影

7 CGContextSetRGBFillColor這只填充顏色

7 CGContextSetRGBStrokeColor 畫筆顏色設(shè)置

7 CGContextSetFillColorSpace 顏色空間填充

7 CGConextSetStrokeColorSpace 顏色空間畫筆設(shè)置

8 CGContextFillRect 補(bǔ)充當(dāng)前填充顏色的rect

8 CGContextSetAlaha 透明度

9 CGContextTranslateCTM 改變畫布位置

10 CGContextSetLineWidth 設(shè)置線的寬度

11 CGContextAddRects 畫多個(gè)線

12 CGContextAddQuadCurveToPoint 畫曲線

13CGContextStrokePath 開始繪制圖片

13 CGContextDrawPath 設(shè)置繪制模式

14 CGContextClosePath 封閉當(dāng)前線路

15 CGContextTranslateCTM(context, 0, rect.size.height);CGContextScaleCTM(context, 1.0, -1.0);反轉(zhuǎn)畫布

16 CGContextSetInterpolationQuality 背景內(nèi)置顏色質(zhì)量等級(jí)

16 CGImageCreateWithImageInRect 從原圖片中取小圖

17字符串的 寫入可用nsstring本身的畫圖方法 - (CGSize)drawInRect:(CGRect)rect withFont:(UIFont *)font lineBreakMode:(UILineBreakMode)lineBreakMode alignment:(UITextAlignment)alignment;來(lái)寫進(jìn)去即可

18對(duì)圖片放大縮小的功能就是慢了點(diǎn)

UIGraphicsBeginImageContext(newSize);

UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

19 CGColorGetComponents() 返回顏色的各個(gè)直 以及透明度 可用只讀const float 來(lái)接收是個(gè)數(shù)組

20 畫圖片 CGImageRefimage=CGImageRetain(img.CGImage);

CGContextDrawImage(context, CGRectMake(10.0,height-

100.0, 90.0, 90.0), image);

21 實(shí)現(xiàn)逐變顏色填充方法 CGContextClip(context);

CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();

CGFloat colors[] =

{

204.0 / 255.0, 224.0 / 255.0, 244.0 / 255.0, 1.00,

29.0 / 255.0, 156.0 / 255.0, 215.0 / 255.0, 1.00,

0.0 / 255.0,50.0 / 255.0, 126.0 / 255.0, 1.00,

};

CGGradientRef gradient = CGGradientCreateWithColorComponents

(rgb, colors, NULL, sizeof(colors)/(sizeof(colors[0])*4));

CGColorSpaceRelease(rgb);

CGContextDrawLinearGradient(context, gradient,CGPointMake

(0.0,0.0) ,CGPointMake(0.0,self.frame.size.height),

kCGGradientDrawsBeforeStartLocation);

22 注:畫完圖后,必須

先用CGContextStrokePath來(lái)描線,即形狀

后用CGContextFillPath來(lái)填充形狀內(nèi)的顏色.

填充一個(gè)路徑的時(shí)候,路徑里面的子路徑都是獨(dú)立填充的。

假如是重疊的路徑,決定一個(gè)點(diǎn)是否被填充,有兩種規(guī)則

1,nonzero winding number rule:非零繞數(shù)規(guī)則,假如一個(gè)點(diǎn)被從左到右跨過,計(jì)數(shù)器+1,從右到左跨過,計(jì)數(shù)器-1,最后,如果結(jié)果是0,那么不填充,如果是非零,那么填充。

2,even-odd rule: 奇偶規(guī)則,假如一個(gè)點(diǎn)被跨過,那么+1,最后是奇數(shù),那么要被填充,偶數(shù)則不填充,和方向沒有關(guān)系。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • --繪圖與濾鏡全面解析 概述 在iOS中可以很容易的開發(fā)出絢麗的界面效果,一方面得益于成功系統(tǒng)的設(shè)計(jì),另一方面得益...
    韓七夏閱讀 2,973評(píng)論 2 10
  • 一:canvas簡(jiǎn)介 1.1什么是canvas? ①:canvas是HTML5提供的一種新標(biāo)簽 ②:HTML5 ...
    GreenHand1閱讀 4,880評(píng)論 2 32
  • Quartz 2D繪圖(CoreGraphics) 1. Quartz概述 Quartz是Mac OS X的Dar...
    北辰青閱讀 913評(píng)論 0 1
  • 一、為什么要寫 從論壇博客到微博,再到公眾號(hào)、簡(jiǎn)書、頭條、一點(diǎn)資訊,寫作的平臺(tái)越來(lái)越豐富。2016年微信公眾號(hào)的數(shù)...
    向右奔跑閱讀 672評(píng)論 1 9
  • 沒有人知道他的身世,年幼時(shí),他總是被亨德萊欺負(fù),心里已有了一絲絲復(fù)仇的火焰。但因?yàn)閯P茜,他不得不忍……讀完《呼嘯山...
    目送時(shí)光閱讀 641評(píng)論 0 5

友情鏈接更多精彩內(nèi)容