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