iOS畫圖總結(jié)
0 CGContextRef context = UIGraphicsGetCurrentCont ext(); 設(shè)置上下文
1 CGContextMoveToPoint 開始畫線
2 CGContextAddLineToPoint 畫直線
4 CGContextAddEllipseInRec t 畫一橢圓
4 CGContextSetLineCap 設(shè)置線條終點(diǎn)形狀
4 CGContextSetLineDash 畫虛線
4 CGContextAddRect 畫一方框
4 CGContextStrokeRect 指定矩形
4 CGContextStrokeRectWithW idth 指定矩形線寬度
4 CGContextStrokeLineSegme nts 一些直線
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 CGContextSetShadowWithCo lor 設(shè)置陰影
7 CGContextSetRGBFillColor 這只填充 顏色
7 CGContextSetRGBStrokeCol or 畫筆顏色設(shè)置
7 CGContextSetFillColorSpa ce 顏色空間填充
7 CGConextSetStrokeColorSp ace 顏色空間畫筆設(shè)置
8 CGContextFillRect 補(bǔ)充當(dāng)前填充顏色的rect
8 CGContextSetAlaha 透明度
9 CGContextTranslateCTM 改變畫布位置
10 CGContextSetLineWidth 設(shè)置線的寬度
11 CGContextAddRects 畫多個(gè)線
12 CGContextAddQuadCurveToP oint 畫曲線
13 CGContextStrokePath 開始繪制 圖片
13 CGContextDrawPath 設(shè)置繪制模式
14 CGContextClosePath 封閉當(dāng)前線路
15 CGContextTranslateCTM(context, 0, rect.size.height); CGContextScaleCTM(context, 1.0, -1.0);反轉(zhuǎn)畫布
16 CGContextSetInterpolatio nQuality 背景內(nèi)置顏色質(zhì)量等級(jí)
16 CGImageCreateWithImageIn Rect 從原圖片中取小圖
17 字符串的寫入可用Nsstring本身的畫圖方法 - (CGSize)drawInRect:(CGRect)rect withFont:(UIFont *)font lineBreakMode:(UILineBreakMode)lineBreakMode alignment:(UITextAlignment)alignment;來(lái)寫進(jìn)去即可
18對(duì)圖片放大縮小的功能就是慢了點(diǎn)
UIGraphicsBeginImageCont ext(newSize);
UIImage* newImage = UIGraphicsGetImageFromCu rrentImageContext();
UIGraphicsEndImageContex t();
19 CGColorGetComponents() 返回顏色的各個(gè)值 以及透明度可用只讀const float 來(lái)接收是個(gè)數(shù)組
20 畫圖片 CGImageRef image =CGImageRetain(img.CGImage);
CGContextDrawImage(context, CGRectMake(10.0, height -
100.0, 90.0, 90.0), image);
21 實(shí)現(xiàn)逐變顏色填充方法 CGContextClip(context);
CGColorSpaceRef rgb = CGColorSpaceCreateDevice RGB();
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 = CGGradientCreateWithColo rComponents
(rgb, colors, NULL, sizeof(colors)/(sizeof(colors[0])*4));
CGColorSpaceRelease(rgb);
CGContextDrawLinearGradi ent(context, gradient,CGPointMake
(0.0,0.0) ,CGPointMake(0.0,self.frame.size.height),
kCGGradientDrawsBeforeSt artLocation);
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)被從左到右跨過(guò),計(jì)數(shù)器+1,從右到左跨過(guò),計(jì)數(shù)器-1,最后,如果結(jié)果是0,那么不填充,如果是非零,那么填充。
2,even-odd rule: 奇偶規(guī)則,假如一個(gè)點(diǎn)被跨過(guò),那么+1,最后是奇數(shù),那么要被填充,偶數(shù)則不填充,和方向沒(méi)有關(guān)系。
Function
Description
CGContextEOFillPath
使用奇偶規(guī)則填充當(dāng)前路徑
CGContextFillPath
使用非零繞數(shù)規(guī)則填充當(dāng)前路徑
CGContextFillRect
填充指定的矩形
CGContextFillRects
填充指定的一些矩形
CGContextFillEllipseInRe ct
填充指定矩形中的橢圓
CGContextDrawPath
兩個(gè)參數(shù)決定填充規(guī)則,kCGPathFill表示用非零繞數(shù)規(guī)則,kCGPathEOFill表示用奇偶規(guī)則,kCGPathFillStroke表示填充,kCGPathEOFillStroke表示描線,不是填充
設(shè)置當(dāng)一個(gè)顏色覆蓋上另外一個(gè)顏色,兩個(gè)顏色怎么混合
默認(rèn)方式是
result = (alpha * foreground) + (1 - alpha) * background
CGContextSetBlendMode :設(shè)置blend mode.
CGContextSaveGState :保存blend mode.
CGContextRestoreGState:在沒(méi)有保存之前,用這個(gè)函數(shù)還原blend mode.
CGContextSetBlendMode 混合倆種顏色