swift 在圖片上根據(jù)點(diǎn)數(shù)組劃線

可直接調(diào)用此方法,傳入imageView和點(diǎn)數(shù)組。

func drawLineInImageWithImage(imageView:UIImageView,points:[CGPoint]){
        UIGraphicsBeginImageContext(imageView.frame.size);
        imageView.image?.drawInRect(CGRectMake(0, 0, imageView.frame.size.width, imageView.frame.size.height));
        CGContextSetLineCap(UIGraphicsGetCurrentContext(), CGLineCap.Round);
        CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
     CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), true);
        CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), self.lineColor.r(),self.lineColor.g(),self.lineColor.b(),self.lineColor.a());
        CGContextBeginPath(UIGraphicsGetCurrentContext());
        let begin = points[0];
        CGContextMoveToPoint(UIGraphicsGetCurrentContext(), begin.x,begin.y);//起點(diǎn)坐標(biāo)
        for point in points{
            CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), point.x, point.y);
        }
        //終點(diǎn)坐標(biāo)
        CGContextStrokePath(UIGraphicsGetCurrentContext());
    imageView.image=UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    }

圖片 1.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 點(diǎn)擊查看原文 Web SDK 開發(fā)手冊(cè) SDK 概述 網(wǎng)易云信 SDK 為 Web 應(yīng)用提供一個(gè)完善的 IM 系統(tǒng)...
    layjoy閱讀 14,290評(píng)論 0 15
  • 第5章 引用類型(返回首頁(yè)) 本章內(nèi)容 使用對(duì)象 創(chuàng)建并操作數(shù)組 理解基本的JavaScript類型 使用基本類型...
    大學(xué)一百閱讀 3,667評(píng)論 0 4
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,525評(píng)論 19 139
  • 2017.02.22 可以練習(xí),每當(dāng)這個(gè)時(shí)候,腦袋就犯困,我這腦袋真是神奇呀,一說(shuō)讓你做事情,你就犯困,你可不要太...
    Carden閱讀 1,490評(píng)論 0 1
  • 百花聊賴敗芬芳 秋風(fēng)不屈送水流 一杯濁酒灌心腸 生死無(wú)懼淡憂愁
    崔凌辰閱讀 142評(píng)論 0 0

友情鏈接更多精彩內(nèi)容