日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

OC画笔CGContextRef

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

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