zoukankan      html  css  js  c++  java
  • iOS 绘图(虚线、椭圆)

    #pragma  画虚线 

      UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 640)];

        imageView1.backgroundColor = [UIColor redColor];

        [self.view addSubview:imageView1];

     

        UIGraphicsBeginImageContext(imageView1.frame.size);   //开始画线

        CGFloat lengths[] = {10,4};  //10个点,空4个点

        CGContextRef line = UIGraphicsGetCurrentContext(); //设置上下文

        CGContextSetStrokeColorWithColor(line, [UIColor blackColor].CGColor);

        

        CGContextSetLineDash(line, 0, lengths, 2);  //画虚线

        CGContextMoveToPoint(line, 100.0, 10.0);    //开始画线,设置X,Y的起点位置

        CGContextAddLineToPoint(line, 300.0,550.0); //线终点的X,Y位置

        CGContextStrokePath(line); //填充

        

        imageView1.image = UIGraphicsGetImageFromCurrentImageContext();

     

     

    #pragma 画椭圆

        UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 640)];

        [self.view addSubview:imageView1];

        UIGraphicsBeginImageContext(imageView1.frame.size);   //开始画线

        [imageView1.image drawInRect:CGRectMake(0, 0, imageView1.frame.size.width, imageView1.frame.size.height)];

        CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);  //设置线条终点形状

        CGFloat lengths[] = {10,10};

        CGContextRef ellipse = UIGraphicsGetCurrentContext();

        CGContextSetStrokeColorWithColor(ellipse, [UIColor redColor].CGColor);

        CGContextSetLineDash(ellipse, 0, lengths, 2);  //画虚线园

        CGRect rectangle = CGRectMake(0,0,200,80);

        CGContextAddEllipseInRect(ellipse,rectangle);

        CGContextStrokePath(ellipse);

        imageView1.image = UIGraphicsGetImageFromCurrentImageContext();

     

  • 相关阅读:
    Openwrt单独编译某一个模块而不是整个固件
    在ubuntu 14.04 编译android 2.3.1 错误解决办法
    使用cydia substrate 来进行android native hook
    使用Privoxy转化SSH到HTTP代理
    使用xposed 来解阿里ctf-2014 第三题
    一个android dex 转java源码工具
    git CVE-2014-9390 验证以及源码对比
    一键结束port 5037占用
    运动物体检测——光流法(摄像机固定)
    运动目标检测ViBe算法
  • 原文地址:https://www.cnblogs.com/i0ject/p/4094507.html
Copyright © 2011-2022 走看看