iOS Quart 2D ------------> CGContextRef

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

1 CGContextMoveToPoint 開始畫

2 CGContextAddLineToPoint 畫直


4 CGContextAddEllipseInRect 畫一橢圓

4 CGContextSetLineCap 設置線條終點形狀

4 CGContextSetLineDash 畫虛

4 CGContextAddRect 畫一方框

4 CGContextStrokeRect 指定矩形

4 CGContextStrokeRectWithWidth 指定矩形線寬度

4 CGContextStrokeLineSegments 一些直

畫一實心圓

CGContextFillEllipseInRect(context, CGRectMake(95, 95, 10.0, 10));


5 CGContextAddArc 畫已曲 倆店爲中心 間倆店爲起始弧度 最後一數據0則順時針畫 1則逆時針

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

6 CGContextSetShadowWithColor 設置陰影

7 CGContextSetRGBFillColor 這隻填充顏色

7 CGContextSetRGBStrokeColor 畫筆顏色設置

7 CGContextSetFillColorSpace 顏色空間填充

7 CGConextSetStrokeColorSpace 顏色空間畫筆設置

8 CGContextFillRect 補充當前填充顏色的rect

8 CGContextSetAlaha 透明度


9 CGContextTranslateCTM 變畫布位置

10 CGContextSetLineWidth 設置線的寬度

11 CGContextAddRects 畫多個

12 CGContextAddQuadCurveToPoint 畫曲

13  CGContextStrokePath 開始繪製圖片

13 CGContextDrawPath 設置繪製模式

14 CGContextClosePath 閉當前線路

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

16 CGContextSetInterpolationQuality 背景內置顏色質量等級

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 來接收  是個數


20  CGImageRef imageCGImageRetain(img.CGImage);

     CGContextDrawImage(context, CGRectMake(10.0, height -              

     100.0, 90.0, 90.0), image);


21 實現逐變顏色填充方法 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來填充形狀內的顏色



填充一個路徑的時候,路徑裏面的子路徑都是獨立填充的。

假如是重疊的路徑,決定一個點是否被填充,有兩種規則

1,nonzero winding number rule:非零繞數規則,假如一個點被從左到右跨過,計數器+1,從右到左跨過,計數器-1,最後,如果結果是0,那麼不填充,如果是非零,那麼填充。

2,even-odd rule: 奇偶規則,假如一個點被跨過,那麼+1,最後是奇數,那麼要被填充,偶數則不填充,和方向沒有關係。


 

 Function

Description 

 CGContextEOFillPath

 使用奇偶規則填充當前路徑

 CGContextFillPath

 使用非零繞數規則填充當前路徑

 CGContextFillRect

 填充指定的矩形

 CGContextFillRects

 填充指定的一些矩形

 CGContextFillEllipseInRect

 填充指定矩形中的橢圓

 CGContextDrawPath

 兩個參數決定填充規則,kCGPathFill表示用非零繞數規則,kCGPathEOFill表示用奇偶規則,kCGPathFillStroke表示填充,kCGPathEOFillStroke表示描線,不是填充






設置當一個顏色覆蓋上另外一個顏色,兩個顏色怎麼混合

認方式是

result = (alpha * foreground) + (1 - alpha) * background


CGContextSetBlendMode :設置blend mode.

CGContextSaveGState :保存blend mode.

CGContextRestoreGState:在沒有保存之前,用這個函數還原blend mode.

CGContextSetBlendMode 混合倆種顏色



指定路徑

CGContextAddArc 前添加的一段弧

CGContextAddArcToPoint 添加一個

CGContextAddCurveToPoint追加當前的曲

CGContextAddLines 添加多條曲

CGContextAddLineToPoint 一個線段終點

CGContextAddPath 添加到當前上下文路徑

CGContextAddQuadCurveToPoint 追加當前點,使用你指定的點

CGContextAddRects矩形路徑添加到當前點


置畫筆

[[UIColor orangeColor] setStroke];

CGContextClosePath 閉和終止當前路徑的子路徑 【使用此函數那麼所有的都是閉合的線路】

發佈了11 篇原創文章 · 獲贊 0 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章