swift 在图片上根据点数组划线

可直接调用此方法,传入imageView和点数组。

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);//起点坐标
        for point in points{
            CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), point.x, point.y);
        }
        //终点坐标
        CGContextStrokePath(UIGraphicsGetCurrentContext());
    imageView.image=UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    }

图片 1.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 点击查看原文 Web SDK 开发手册 SDK 概述 网易云信 SDK 为 Web 应用提供一个完善的 IM 系统...
    layjoy阅读 13,984评论 0 15
  • 第5章 引用类型(返回首页) 本章内容 使用对象 创建并操作数组 理解基本的JavaScript类型 使用基本类型...
    大学一百阅读 3,272评论 0 4
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,067评论 19 139
  • 2017.02.22 可以练习,每当这个时候,脑袋就犯困,我这脑袋真是神奇呀,一说让你做事情,你就犯困,你可不要太...
    Carden阅读 1,388评论 0 1
  • 百花聊赖败芬芳 秋风不屈送水流 一杯浊酒灌心肠 生死无惧淡忧愁
    崔凌辰阅读 137评论 0 0