OC画笔CGContextRef
1.畫線
? CGContextRef context = UIGraphicsGetCurrentContext();//context相當于畫布
? CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);//設置線得顏色
?CGContextMoveToPoint(context, 100, 100);//畫筆的起始點
?CGContextAddLineToPoint(context, 150, 150);//畫筆的終點
?CGContextStrokePath(context);//繪畫結束
2.畫圓
?? CGContextRef context = UIGraphicsGetCurrentContext();//context相當于畫布
?? //CGContextAddArc(<#CGContextRef c#>, <#CGFloat x#>, <#CGFloat y#>, <#CGFloat radius#>, <#CGFloat startAngle#>, <#CGFloat endAngle#>, <#int clockwise#>)
? CGContextAddArc(context, 100, 100, 50, M_PI, M_PI*3/2, 0);// x y 相當于圓心? radius半徑 startAngle起始弧度 endAngle終止弧度 clockwise 0為順時針,1為逆時針
? CGContextStrokePath(context);
3.畫一個有填充色的矩形
? CGContextRef context = UIGraphicsGetCurrentContext();//得到畫布
? CGContextSetFillColorWithColor(context, [UIColor blueColor].CGColor);//設置矩形的填充色
? CGContextAddRect(context, CGRectMake(100, 200, 100, 200));// x,y起始點? width 寬度? height 高度
? CGContextFillPath(context);//填充矩形
? CGContextStrokePath(context);//繪畫結束
?4.畫圖
?UIGraphicsBeginImageContext(self.view.bounds.size);???? //currentView 當前的view? 創建一個基于位圖的圖形上下文并指定大小
?[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];//renderInContext呈現接受者及其子范圍到指定的上下文
?UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();//返回一個基于當前圖形上下文的圖片
?UIGraphicsEndImageContext();//移除棧頂的基于當前位圖的圖形上下文
?UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);//然后將該圖片保存到圖片圖
轉載于:https://www.cnblogs.com/hualuoshuijia/p/4997551.html
總結
以上是生活随笔為你收集整理的OC画笔CGContextRef的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ELF Format 笔记(十三)——
- 下一篇: 转: 学ppt的网址与素材