Quartz2D總結,iosquartz2d

來源:互聯網
上載者:User

Quartz2D總結,iosquartz2d

天了嚕,腦子完全懵了,最起碼說出來個上下文啊,連這個都給忘了,特此總結一下,並以此緬懷這次面試

 

Quartz2D的API來自於Core Graphics(這就是為什麼CGContextRef是以CG開頭),需要匯入CoreGraphics(?)

圖形上下文:是一個CGContextRef類型的資料

圖形內容相關的作用:

1.儲存繪圖資訊、繪圖狀態

2.決定繪製的輸出目標(繪製到什麼地方去)(輸出目標可以是PDF檔案、Bitmap或者顯示器的視窗上

Bitmap Graphics ContextPDF Graphics ContextWindow Graphics ContextLayer Graphics ContextPrinter Graphics Context

自己畫一個view
步驟:
1.建立一個類,繼承自UIView
2.實現- (void)drawRect:(CGRect)rect方法,並在此方法中取得當前view的圖形上下文
3.建立自己的繪製path,並根據path來繪製圖形
4.利用圖形上下文將繪製的所有內容渲染顯示到view上面

當然,比如Bitmap的圖形上下文就不必在- (void)drawRect:(CGRect)rect裡面了,直接建立一個就可:
// 建立一個bitmap上下文    UIGraphicsBeginImageContextWithOptions(CGSizeMake(200, 200), NO, 0);     // 擷取bitmap上下文    CGContextRef ctr = UIGraphicsGetCurrentContext();    // 畫圓    CGContextAddEllipseInRect(ctr, CGRectMake(50, 50, 100, 100));    // 渲染    CGContextStrokePath(ctr); // 從上下文擷取畫出的圖片    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();    UIImageView *imageView = [[UIImageView alloc] initWithImage:img];    CGRect frame = imageView.frame;    frame.origin = CGPointMake(50, 50);    imageView.frame = frame;    [self.view addSubview:imageView];

待續。。。

部分參考自:http://www.jianshu.com/p/eecffec3b7af



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.