Quartz2D知识点聚合案例
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知识点聚合案例的更多相关文章
- 白日梦的Elasticsearch实战笔记,ES账号免费借用、32个查询案例、15个聚合案例、7个查询优化技巧。
目录 一.导读 二.福利:账号借用 三._search api 搜索api 3.1.什么是query string search? 3.2.什么是query dsl? 3.3.干货!32个查询案例! ...
- 白日梦的Elasticsearch实战笔记,32个查询案例、15个聚合案例、7个查询优化技巧。
目录 一.导读 三._search api 搜索api 3.1.什么是query string search? 3.2.什么是query dsl? 3.3.干货!32个查询案例! 四.聚合分析 4.1 ...
- 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 ...
- postgres多知识点综合案例
使用到的知识点: 1.使用with临时存储sql语句,格式[with as xxx(), as xxx2() ]以减少代码: 2.使用round()取小数点后几位: 3.使用to_char()将时间格 ...
- pandas分组聚合案例
美国2012年总统候选人政治献金数据分析 导入包 import numpy as np import pandas as pd from pandas import Series,DataFrame ...
- 细嚼JS闭包知识点及案例分析
闭包是js开发惯用的技巧,什么是闭包? 闭包指的是:能够访问另一个函数作用域的变量的函数.清晰的讲:闭包就是一个函数,这个函数能够访问其他函数的作用域中的变量.默认闭包的this指向windows. ...
- django 中的聚合和分组 F查询 Q查询 事务cookies和sessions 066
1 聚合和分组 聚合:对一些数据进行整理分析 进而得到结果(mysql中的聚合函数) 1aggregate(*args,**kwargs) : 通过对QuerySet进行计算 ,返回一个聚合值的字典. ...
- 042 01 Android 零基础入门 01 Java基础语法 05 Java流程控制之循环结构 04 案例演示while循环的使用——循环输出英文字母
042 01 Android 零基础入门 01 Java基础语法 05 Java流程控制之循环结构 04 案例演示while循环的使用--循环输出英文字母 本文知识点:案例演示while循环的使用2 ...
- 041 01 Android 零基础入门 01 Java基础语法 05 Java流程控制之循环结构 03 案例演示while循环的使用——求1到5的累加和
041 01 Android 零基础入门 01 Java基础语法 05 Java流程控制之循环结构 03 案例演示while循环的使用--求1到5的累加和 本文知识点:案例演示while循环的使用1 ...
随机推荐
- CXF 中自定义SOAPHeader
Interceptor是CXF架构中一个很有特色的模式.你可以在不对核心模块进行修改的情况下,动态添加很多功能.这对于CXF这个以处理消息为中心的服务框架来说是非常有用的,CXF通过在Intercep ...
- XMU 1608 nc与加法进位 【二分】
1608: nc与加法进位 Time Limit: 2000 MS Memory Limit: 128 MBSubmit: 29 Solved: 27[Submit][Status][Web Bo ...
- RK3288以太网的mac地址调试笔记【学习笔记】【原创】
平台信息:内核:linux3.1.0系统:android/android6.0平台:RK3288 作者:庄泽彬(欢迎转载,请注明作者) 邮箱:2760715357@qq.com 说明:提供以太网mac ...
- caioj1272&&codeforces 148D: 概率期望值3:抓老鼠
这道真的是好题,不卡精度,不卡细节,但是思考的方式很巧妙! 一开始大家跟我想的应该差不多,用f[i][j]表示有i只白老鼠,j只黑老鼠的胜率,然后跑DP,然后我就发现,这样怎么做?还有一种不胜不负的平 ...
- AngularJS 指令(Directives)实践指南
指令(Directives)是所有AngularJS应用最重要的部分.尽管AngularJS已经提供了非常丰富的指令,但还是经常需要创建应用特定的指令.这篇教程会为你讲述如何自定义指令,以及介绍如何在 ...
- Java 基本类型和对象类型的区别
Java 基本类型和对象类型的区别 基本类型: int long byte float double char boolean short 对象类型: Integer Long Byte Float ...
- BZOJ_3209_花神的数论题_组合数+数位DP
BZOJ_3209_花神的数论题_组合数+数位DP Description 背景 众所周知,花神多年来凭借无边的神力狂虐各大 OJ.OI.CF.TC …… 当然也包括 CH 啦. 描述 话说花神这天又 ...
- 转3xian之所在 (一位ACM大牛的博文)
3xian的经历和见解...我深思... 最后一天,漫天飘起了雪花,假装欢送我离去. 这次WF之战不太顺利,早期的C题大概花了1秒钟构思,然而由于输出格式多了一个空格直到两个半小时才逃脱Wrong A ...
- cmath函数整理
double a= pow(double x, double y)://返回x的y次方. double a= sqrt(double x)://返回x的平方根. double a=ceil(doubl ...
- 10_传智播客iOS视频教程_NSString
从今天开始不会再去用C语言当中的字符串.因为OC当中设计了一种更为好用的存储字符串的变量. C的字符串和OC的字符串是有区别的. NSString类型的指针变量,只能存储OC字符串的地址.第一步是声明 ...