原文鏈接如下:
http://blog.csdn.net/zhenyu5211314/article/details/24230581?utm_source=tuicool&utm_medium=referral
0 CGContextRef context = UIGraphicsGetCurrentContext(); 設(shè)置上下文
1 CGContextMoveToPoint 開始畫線
2 CGContextAddLineToPoint 畫直線
4 CGContextAddEllipseInRect 畫一橢圓
4 CGContextSetLineCap 設(shè)置線條終點形狀
4 CGContextSetLineDash 畫虛線
4 CGContextAddRect 畫一方框
4 CGContextStrokeRect 指定矩形
4 CGContextStrokeRectWithWidth 指定矩形線寬度
4 CGContextStrokeLineSegments 一些直線
5 CGContextAddArc 畫一曲線 前兩點為中心 中間倆店為起始弧度 最后一數(shù)據(jù)為0則順時針畫 1則逆時針
5 CGContextAddArcToPoint(context,0,0, 2, 9, 40);//先畫兩條線從point 到 第1點 , 從第1點到第2點的線 切割里面的圓
6 CGContextSetShadowWithColor 設(shè)置陰影
7 CGContextSetRGBFillColor 這只填充顏色
7 CGContextSetRGBStrokeColor 畫筆顏色設(shè)置
7 CGContextSetFillColorSpace 顏色空間填充
7 CGConextSetStrokeColorSpace 顏色空間畫筆設(shè)置
8 CGContextFillRect 補充當前填充顏色的rect
8 CGContextSetAlaha 透明度
9 CGContextTranslateCTM 改變畫布位置
10 CGContextSetLineWidth 設(shè)置線的寬度
11 CGContextAddRects 畫多個線
12 CGContextAddQuadCurveToPoint 畫曲線
13 CGContextStrokePath 開始繪制圖片
13 CGContextDrawPath 設(shè)置繪制模式
14 CGContextClosePath 封閉當前線路
15 CGContextTranslateCTM(context, 0, rect.size.height); CGContextScaleCTM(context, 1.0, -1.0);反轉(zhuǎn)畫布
16 CGContextSetInterpolationQuality 背景內(nèi)置顏色質(zhì)量等級
16 CGImageCreateWithImageInRect 從原圖片中取小圖
17 字符串的 寫入可用 nsstring本身的畫圖方法 - (CGSize)drawInRect:(CGRect)rect withFont:(UIFont *)font lineBreakMode:(UILineBreakMode)lineBreakMode alignment:(UITextAlignment)alignment;來寫進去即可
18對圖片放大縮小的功能就是慢了點
UIGraphicsBeginImageContext(newSize);
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
19 CGColorGetComponents() 返回顏色的各個直 以及透明度 可用只讀const float 來接收 是個數(shù)組
20 畫圖片 CGImageRef image=CGImageRetain(img.CGImage);
CGContextDrawImage(context, CGRectMake(10.0, height -
100.0, 90.0, 90.0), image);
21 實現(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來描線,即形狀
后用CGContextFillPath來填充形狀內(nèi)的顏色.
填充一個路徑的時候,路徑里面的子路徑都是獨立填充的枚赡。
假如是重疊的路徑氓癌,決定一個點是否被填充,有兩種規(guī)則
1,nonzero winding number rule:非零繞數(shù)規(guī)則贫橙,假如一個點被從左到右跨過贪婉,計數(shù)器+1,從右到左跨過卢肃,計數(shù)器-1疲迂,最后,如果結(jié)果是0践剂,那么不填充鬼譬,如果是非零,那么填充逊脯。
2,even-odd rule: 奇偶規(guī)則优质,假如一個點被跨過,那么+1军洼,最后是奇數(shù)巩螃,那么要被填充,偶數(shù)則不填充匕争,和方向沒有關(guān)系避乏。
Function
Description
CGContextEOFillPath
使用奇偶規(guī)則填充當前路徑
CGContextFillPath
使用非零繞數(shù)規(guī)則填充當前路徑
CGContextFillRect
填充指定的矩形
CGContextFillRects
填充指定的一些矩形
CGContextFillEllipseInRect
填充指定矩形中的橢圓
CGContextDrawPath
兩個參數(shù)決定填充規(guī)則,kCGPathFill表示用非零繞數(shù)規(guī)則甘桑,kCGPathEOFill表示用奇偶規(guī)則拍皮,kCGPathFillStroke表示填充,kCGPathEOFillStroke表示描線跑杭,不是填充
設(shè)置當一個顏色覆蓋上另外一個顏色铆帽,兩個顏色怎么混合
默認方式是
result = (alpha * foreground) + (1 - alpha) * background
CGContextSetBlendMode :設(shè)置blend mode.
CGContextSaveGState :保存blend mode.
CGContextRestoreGState:在沒有保存之前,用這個函數(shù)還原blend mode.
CGContextSetBlendMode 混合倆種顏色