美文网首页
iOS 绘图

iOS 绘图

作者: Rumbles | 来源:发表于2019-06-25 16:46 被阅读0次

    1.Quart2D绘图 绘图(CGcontext)

    绘制简单的直线
        CGContextRef ctx = UIGraphicsGetCurrentContext();
        CGContextMoveToPoint(ctx, 14, 19);
        CGContextAddLineToPoint(ctx, 45, 65);
        CGContextStrokePath(ctx);
    

    2.贝塞尔曲线

    绘制简单的直线
        UIBezierPath *linePath = [UIBezierPath bezierPath];
        [linePath moveToPoint:(CGPoint){20,20}];
        [linePath addLineToPoint:(CGPoint){160,160}];
        [linePath addLineToPoint:(CGPoint){200,20}];
    

    3. 贝塞尔曲线 与 CGcontext 结合

       //使用贝塞尔曲线和图形上下文画图
        CGContextRef ctx = UIGraphicsGetCurrentContext();
        UIBezierPath *path = [UIBezierPath bezierPath];
        [path moveToPoint:CGPointZero];
        [path addLineToPoint:CGPointMake(233, 69)];
       //这个是C语言的写法,必须使用path.CGPath,否则无效
        CGContextAddPath(ctx, path.CGPath);
        CGContextStrokePath(ctx);
    

    4.贝塞尔曲线放在layer上

        UIBezierPath *linePath = [UIBezierPath bezierPath];
        [linePath moveToPoint:(CGPoint){20,20}];
        [linePath addLineToPoint:(CGPoint){160,160}];
        [linePath addLineToPoint:(CGPoint){200,20}];
        
        CAShapeLayer *layer = [CAShapeLayer layer];
        layer.frame = CGRectMake(0, 0, 200, 200);
        layer.position = (CGPoint){ScreenWidth/2,ScreenWidth/2};
        layer.lineWidth = 5;
        layer.strokeColor = [UIColor orangeColor].CGColor;
        layer.path = linePath.CGPath;
        layer.fillColor = nil; // 默认是黑色
        layer.lineCap = kCALineCapRound;
        
        [_disPlayView.layer addSublayer:layer];
    

    5.将 (CGcontext) 绘制在image上面

        UIGraphicsBeginImageContextWithOptions(self.frame.size, NO, 0);
        CGContextRef ctx = UIGraphicsGetCurrentContext();
        CGContextMoveToPoint(ctx, 14, 19);
        CGContextAddLineToPoint(ctx, 45, 65);
        CGContextStrokePath(ctx);
        image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    

    CGcontext API
    UIGraphicsBeginImage 对图片的处理

    Quart2D绘图之UIGraphicsGetCurrentContext基础

    相关文章

      网友评论

          本文标题:iOS 绘图

          本文链接:https://www.haomeiwen.com/subject/srxxcctx.html