日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

OC画笔CGContextRef

發布時間:2025/7/14 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。