Quartz2D知识点聚合

基本

     //画图片
UIImage *image = [UIImage imageNamed:@"阿狸头像"];
[image drawInRect:rect]; //字体
NSString *title = @"标题";
NSMutableDictionary *atr = [NSMutableDictionary dictionary];
atr[NSFontAttributeName] = [UIFont systemFontOfSize:15];
// atr[NSForegroundœColorAttributeName] = [UIColor greenColor];
[title drawInRect:CGRectMake(120, 20, 100, 20) withAttributes:atr]; //椭圆
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(10, 20, 70, 130)];
[path stroke]; //方形
UIBezierPath *path1 = [UIBezierPath bezierPathWithRect:CGRectMake(10, 200, 10, 50)]; [path1 stroke]; //圆角方形
UIBezierPath *path2 = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(100, 30, 100, 100) cornerRadius:10];
[path2 stroke]; //一个角圆角
UIBezierPath *path3 = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(210, 90, 80, 70) byRoundingCorners:UIRectCornerTopRight cornerRadii:CGSizeMake(20, 30)];
[path3 stroke]; //圆弧
UIBezierPath *path4 = [UIBezierPath bezierPathWithArcCenter:CGPointMake(130, 230) radius:70 startAngle:0 endAngle:M_PI clockwise:YES];
[path4 stroke];
// 1.获得当前上下文
CGContextRef ctx = UIGraphicsGetCurrentContext(); // 2.拼接路径
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(10, 20)];
[path addQuadCurveToPoint:CGPointMake(200, 80) controlPoint:CGPointMake(100, 200)]; // 3. 添加路径到上下文
CGContextAddPath(ctx, path.CGPath); // 4.渲染上下文
CGContextStrokePath(ctx);

变换

    //变换
//平移
// CGContextTranslateCTM(ctx, 10, 20);
//旋转
CGContextRotateCTM(ctx, M_PI_4);
//缩放
CGContextScaleCTM(ctx, 1.2, 1.2);

上下文栈

  • 先保存或者还原上下文栈,再设置状态
// 1.获得当前上下文
CGContextRef ctx = UIGraphicsGetCurrentContext(); // 2.拼接路径
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(10, 20)];
[path addQuadCurveToPoint:CGPointMake(200, 80) controlPoint:CGPointMake(100, 200)]; // 3. 添加路径到上下文
CGContextAddPath(ctx, path.CGPath); //保存上下文
CGContextSaveGState(ctx); //设置上下文状态
CGContextSetLineWidth(ctx, 10);
[[UIColor redColor] set]; // 4.渲染上下文
CGContextStrokePath(ctx); // 2.拼接路径
path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(100, 80)];
[path addLineToPoint:CGPointMake(200, 200)]; // 3. 添加路径到上下文
CGContextAddPath(ctx, path.CGPath);
//还原上下文
CGContextRestoreGState(ctx);
//设置上下文状态
CGContextSetLineWidth(ctx, 5);
[[UIColor blueColor] set]; // 4.渲染上下文
CGContextStrokePath(ctx);

生成图片

    UIImage *image = [UIImage imageNamed:@"小黄人"];
UIGraphicsBeginImageContextWithOptions(image.size, YES, 0); [image drawAtPoint:CGPointZero]; NSString *str = @"小黄人"; [str drawAtPoint:CGPointZero withAttributes:nil]; image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();

截图

  • 给定裁减区域再渲染
    //开启图片上下文
UIGraphicsBeginImageContext(view.frame.size);
//获得当前上下文
CGContextRef ctx = UIGraphicsGetCurrentContext(); //给定裁减区域-----
//渲染图片
[view.layer renderInContext:ctx]; //从当前上下文得到一张图片
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); //关闭图片上下文
UIGraphicsEndImageContext(); return image;

擦除

  • 先渲染到上下文,再擦除
 UITouch *touch = [touches anyObject];

    CGPoint point = [touch locationInView:self.imageView];

    //开启上下文
UIGraphicsBeginImageContextWithOptions(self.imageView.frame.size, NO, 0); //获得当前上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
//渲染到上下文
[self.imageView.layer renderInContext:ctx]; //获取擦除区域
CGRect rect = CGRectMake(point.x - 10, point.y - 10, 20, 20);
// 擦除上下文的内容
CGContextClearRect(ctx, rect); // 生成图片
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); _imageView.image = image;
// 关闭上下文
UIGraphicsEndImageContext();

Quartz2D知识点聚合案例的更多相关文章

  1. 白日梦的Elasticsearch实战笔记,ES账号免费借用、32个查询案例、15个聚合案例、7个查询优化技巧。

    目录 一.导读 二.福利:账号借用 三._search api 搜索api 3.1.什么是query string search? 3.2.什么是query dsl? 3.3.干货!32个查询案例! ...

  2. 白日梦的Elasticsearch实战笔记,32个查询案例、15个聚合案例、7个查询优化技巧。

    目录 一.导读 三._search api 搜索api 3.1.什么是query string search? 3.2.什么是query dsl? 3.3.干货!32个查询案例! 四.聚合分析 4.1 ...

  3. elasticsearch聚合案例--分组、求最大值再求最大值的均值

    一.需求 A.B.C代表3个用户,第二列代表各自的得分,求A.B.C的最好成绩以及A.B.C最好成绩的均值 A 10 A 11 A 13 B 11 B 11 B 12 C 10 C 10 C 11 C ...

  4. postgres多知识点综合案例

    使用到的知识点: 1.使用with临时存储sql语句,格式[with as xxx(), as xxx2() ]以减少代码: 2.使用round()取小数点后几位: 3.使用to_char()将时间格 ...

  5. pandas分组聚合案例

    美国2012年总统候选人政治献金数据分析 导入包 import numpy as np import pandas as pd from pandas import Series,DataFrame ...

  6. 细嚼JS闭包知识点及案例分析

    闭包是js开发惯用的技巧,什么是闭包? 闭包指的是:能够访问另一个函数作用域的变量的函数.清晰的讲:闭包就是一个函数,这个函数能够访问其他函数的作用域中的变量.默认闭包的this指向windows. ...

  7. django 中的聚合和分组 F查询 Q查询 事务cookies和sessions 066

    1 聚合和分组 聚合:对一些数据进行整理分析 进而得到结果(mysql中的聚合函数) 1aggregate(*args,**kwargs) : 通过对QuerySet进行计算 ,返回一个聚合值的字典. ...

  8. 042 01 Android 零基础入门 01 Java基础语法 05 Java流程控制之循环结构 04 案例演示while循环的使用——循环输出英文字母

    042 01 Android 零基础入门 01 Java基础语法 05 Java流程控制之循环结构 04 案例演示while循环的使用--循环输出英文字母 本文知识点:案例演示while循环的使用2 ...

  9. 041 01 Android 零基础入门 01 Java基础语法 05 Java流程控制之循环结构 03 案例演示while循环的使用——求1到5的累加和

    041 01 Android 零基础入门 01 Java基础语法 05 Java流程控制之循环结构 03 案例演示while循环的使用--求1到5的累加和 本文知识点:案例演示while循环的使用1 ...

随机推荐

  1. Linux服务基础命令

    ---恢复内容开始--- 1简介: Linux的网络功能相当强悍,一时之间我们无法了解所有的文阿罗命令,在配置服务器基础环境时,先了解下网络参数设定命令. ifconfig     查询,设置网卡和i ...

  2. C项目实践--图书管理系统(4)

    前面已经把图书管理系统的所有功能模块都已实现完毕了,下面通过运行来分析该系统的操作流程并检验是否符合逻辑设计要求. 3.系统操作过程 F5 运行 1.登录系统 系统运行之后,提示输入用户名和密码,系统 ...

  3. zTree 基本用法

    [简介] zTree 是利用 JQuery 的核心代码,实现一套能完成大部分常用功能的 Tree 插件 兼容 IE.FireFox.Chrome 等浏览器 在一个页面内可同时生成多个 Tree 实例 ...

  4. AutoIT: 对数据库的访问,数据提取操作

    #include<array.au3> $conn= ObjCreate("ADODB.Connection") $RS= ObjCreate("ADODB. ...

  5. windows 2003 server 64 位 IIS 6下部署 32位网站

    在 C:\WINDOWS\system32\inetsrv\MetaBase.xml 设置节点 在 开始--->运行--->输入一下代码,回车即可,就会跳出正在安装NET2.0 代码为   ...

  6. 08_传智播客iOS视频教程_Foundation框架

    比如产生随机数.这个功能要你写吗?不用,因为苹果已经写好了.后面想开发一个ios程序,往界面上放一个按钮,实际上这个按钮不用你写别人已经写好了,你就拿过来拖一下就可以了. 框架是1个功能集 苹果或者第 ...

  7. 【黑金教程笔记之003】【建模篇】【Lab 02 闪耀灯和流水灯】—笔记

    (1)       扫描频率和闪耀频率? 模块: /**************************************** module name:flash_module function ...

  8. 在Visual studio 中解除 TFS 的账号绑定

    在Visual Studio中, 只要使用了TFS, 就会要求输入用户名密码验证 . 但是一旦点击验证对话框下部的:记住用户名密码 以后都不能再修改用户名了. 而且重装Visual Studio 听说 ...

  9. Luogu P1083 借教室【二分答案/差分】By cellur925

    题目描述 Description 在大学期间,经常需要租借教室.大到院系举办活动,小到学习小组自习讨论,都需要 向学校申请借教室.教室的大小功能不同,借教室人的身份不同,借教室的手续也不一样. 面对海 ...

  10. 组合数学练习题(一)——Chemist

    题意: 从 n 个人中选出不超过 k 个人,再在选出的人中选出一些人成为队员,再在队员中选一名队长,求不同的方案数.答案 mod 8388608. 共有T组询问,每次给你n和k.T ≤ 10^4 k ...