美文网首页
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绘图详解(链接)

    iOS绘图详解iOS绘图教程

  • iOS 绘图

    转自:iOS绘图—— UIBezierPath 和 Core Graphics绘图进阶请参考:绘图 前言 iOS系...

  • iOS绘图框架CoreGraphics分析

    iOS绘图框架CoreGraphics分析 iOS绘图框架CoreGraphics分析

  • IOS 学习之绘图( Core Graphics 教学)

    IOS 绘图 总结 Core Graphics IOS中绘图的三种方式 在UIKit控件中,的drawInReat...

  • ios绘图基础

    ios绘图才一些场合很好用,这里演示一些基本的方法。 -1 ios绘图基础 -2 ios常见的图形绘制 代码下载:...

  • 绘图

    IOS中绘图的方式介绍 IOS中貌似绘图的方式还挺多的,有 Core Graphics/QuartZ 2D UIK...

  • iOS绘图功能(一)

    不同的绘图系统### iOS主要的绘图系统有UIKit,Core Graphics(Quartz), Core A...

  • 绘图1

    iOS中绘图的概念 iOS iOSopenGL Quartz UIView DrawRect 1个像素 =...

  • iOS-绘图Quartz 2D 贝赛尔曲线相关

    本篇涵盖iOS中绘图上下文,截屏相关等. 1.玩转iOS中的绘图(Quartz 2D基础篇)2.分享iOS中常用的...

  • iOS Quart2D绘图

    iOS Quart2D绘图之UIGraphicsGetCurrentContext基础。 iOS Quart2D绘...

网友评论

      本文标题:iOS 绘图

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