Quartz画图函数笔记
0 CGContextRef context = UIGraphicsGetCurrentContext(); 设置上下文
1 CGContextMoveToPoint 开始画线
2 CGContextAddLineToPoint 画直线
4 CGContextAddEllipseInRect 画一椭圆
4 CGContextSetLineCap 设置线条终点形状
4 CGContextSetLineDash 画虚线
4 CGContextAddRect 画一方框
4 CGContextStrokeRect 指定矩形
4 CGContextStrokeRectWithWidth 指定矩形线宽度
4 CGContextStrokeLineSegments 一些直线
5 CGContextAddArc 画已曲线 前俩店为中心 中间俩店为起始弧度 最后一数据为0则顺时针画 1则逆时针
5 CGContextAddArcToPoint(context,0,0, 2, 9, 40);//先画俩条线从point 到 弟1点 , 从弟1点到弟2点的线 切割里面的圆
6 CGContextSetShadowWithColor 设置阴影
7 CGContextSetRGBFillColor 这只填充 颜色
7 CGContextSetRGBStrokeColor 画笔颜色设置
7 CGContextSetFillColorSpace 颜色空间填充
7 CGConextSetStrokeColorSpace 颜色空间画笔设置
8 CGContextFillRect 补充当前填充颜色的rect
8 CGContextSetAlaha 透明度
9 CGContextTranslateCTM 改变画布位置
10 CGContextSetLineWidth 设置线的宽度
11 CGContextAddRects 画多个线
12 CGContextAddQuadCurveToPoint 画曲线
13 CGContextStrokePath 开始绘制 图片
13 CGContextDrawPath 设置绘制模式
14 CGContextClosePath 封闭当前线路
15 CGContextTranslateCTM(context, 0, rect.size.height); CGContextScaleCTM(context, 1.0, -1.0);反转画布
16 CGContextSetInterpolationQuality 背景内置颜色质量等级
16 CGImageCreateWithImageInRect 从原图片中取小图
17 字符串 的写入可用 nsstring本身的画图方法 - (CGSize)drawInRect:(CGRect)rect withFont:(UIFont *)font lineBreakMode:(UILineBreakMode)lineBreakMode alignment:(UITextAlignment)alignment;来写进去即可
18对图片放大缩小的功能就是慢了点
UIGraphicsBeginImageContext(newSize);
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
19 CGColorGetComponents() 返回颜色的各个直 以及透明度 可用只读const float 来接收 是个 数组
20 画图片 CGImageRef image =CGImageRetain(img.CGImage);
CGContextDrawImage(context, CGRectMake(10.0, height -
100.0, 90.0, 90.0), image);
21 实现逐变颜色填充方法 CGContextClip(context);
CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
CGFloat colors[] =
{
204.0 / 255.0, 224.0 / 255.0, 244.0 / 255.0, 1.00,
29.0 / 255.0, 156.0 / 255.0, 215.0 / 255.0, 1.00,
0.0 / 255.0, 50.0 / 255.0, 126.0 / 255.0, 1.00,
};
CGGradientRef gradient = CGGradientCreateWithColorComponents
(rgb, colors, NULL, sizeof(colors)/(sizeof(colors[0])*4));
CGColorSpaceRelease(rgb);
CGContextDrawLinearGradient(context, gradient,CGPointMake
(0.0,0.0) ,CGPointMake(0.0,self.frame.size.height),
kCGGradientDrawsBeforeStartLocation);
22 注: 画完图后,必须
先用CGContextStrokePath来描线,即形状
后用CGContextFillPath来填充形状内的颜色.
填充一个路径的时候,路径里面的子路径都是独立填充的。
假如是重叠的路径,决定一个点是否被填充,有两种规则
1,nonzero winding number rule:非零绕数规则,假如一个点被从左到右跨过,计数器+1,从右到左跨过,计数器-1,最后,如果结果是0,那么不填充,如果是非零,那么填充。
2,even-odd rule: 奇偶规则,假如一个点被跨过,那么+1,最后是奇数,那么要被填充,偶数则不填充,和方向没有关系。
Function
Description
CGContextEOFillPath
使用奇偶规则填充当前路径
CGContextFillPath
使用非零绕数规则填充当前路径
CGContextFillRect
填充指定的矩形
CGContextFillRects
填充指定的一些矩形
CGContextFillEllipseInRect
填充指定矩形中的椭圆
CGContextDrawPath
两个 参数 决定填充规则,kCGPathFill表示用非零绕数规则,kCGPathEOFill表示用奇偶规则,kCGPathFillStroke表示填充,kCGPathEOFillStroke表示描线,不是填充
设置当一个颜色覆盖上另外一个颜色,两个颜色怎么混合
默认方式是
result = (alpha * foreground) + (1 - alpha) * background
CGContextSetBlendMode :设置blend mode.
CGContextSaveGState :保存blend mode.
CGContextRestoreGState:在没有保存之前,用这个函数还原blend mode.
CGContextSetBlendMode 混合俩种颜色
iPhone图形开发绘图教程是本文要介绍的内容,介绍了很多关于绘图类的使用,先来看详细内容讲解。
1、绘图总结:
绘图前设置:
- CGContextSetRGBFillColor/CGContextSetFillColorWithColor //填充色
- CGContextSetRGBStrokeColor/CGContextSetStrokeColorWithColor //笔颜色
- CGContextSetLineWidth //线宽度
绘图后设置:
注: 画完图后,必须 先用CGContextStrokePath来描线,即形状,后用CGContextFillPath来填充形状内的颜色.
2.常见图形绘制:
- CGContextFillRect/CGContextFillRects
- CGContextFillEllipseInRect
- CGContextAddRect/CGContextAddRects
- CGContextAddEllipseInRect
- CGContextAddLines
- CGContextMoveToPoint
- CGContextAddLineToPoint
3.常见控制方法:
- CGContextSaveGState
- CGContextRestoreGState
4.创建内存图像context:
- CGBitmapContextCreate <-----CGContextRlease释放
- CGColorSpaceCreateWithName (KCGColorSpaceGenericRGB)
- CGColorSpaceRlease
- CGBitmapContextCreateImage() <-----CGImageRlease 释放.
- eg:
- CGContextRefMyCreateBitmapContext(intpixelsWide,intpixelsHigh)
- {
- CGContextRef context=NULL;
- CGColorSpaceRefcolorSpace;
- void* bitmapData;
- int bitmapByteCount;
- int bitmapBytesPerRow;
- bitmapBytesPerRow =(pixelsWide*4);
- bitmapByteCount =(bitmapBytesPerRow*pixelsHigh);
- colorSpace=CGColorSpaceCreateDeviceRGB();
- bitmapData=malloc(bitmapByteCount);
- if(bitmapData==NULL)
- {
- fprintf(stderr,"Memorynotallocated!");
- returnNULL;
- }
- context=CGBitmapContextCreate(bitmapData,
- pixelsWide, pixelsHigh, 8,
- bitmapBytesPerRow, colorSpace,
- kCGImageAlphaPremultipliedLast);
- if(context==NULL)
- {
- free(bitmapData);
- fprintf(stderr,"Contextnotcreated!");
- returnNULL;
- }
- CGColorSpaceRelease(colorSpace);
- returncontext;
- }
5.图形的变换:
- CGContextTranslateCTM
- CGContextRotateCTM
- CGContextScaleCTM
6.常用函数:
- CGRectContainsPoint();
- CGRectContainsRect();
- CGRectIntersectsRect();
- CGRectIntersection();
- CGPointEqualToPoint();
- CGSizeEqualToSize();
7.从原图片中取小图.
- CGImageCreateWithImageInRect
8.屏幕快照:
- #import "QuartzCore/QuartzCore.h"
- UIGraphicsBeginImageContext(yourView.frame.size);
- [[yourView layer] renderInContext:UIGraphicsGetCurrentContext()];
- UIImage*screenshot =UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- from:http://www.cppblog.com/zhangyuntaoshe/articles/123066.html
合并两张bit图到一张image的方法
- To graphically merge two images into a new image, you do something like this:
- UIImage *result = nil;
- unsignedchar *data = calloc(1,size.width*size.height*kBytesPerPixel);
- if (data != NULL) {
- // kCGImageAlphaPremultipliedLast 为预记录的#define value
- // 设置context上下文
- CGContextRef context = CGBitmapContextCreate(
- data, size.width, size.height, 8, size.width*kBytesPerPixel,
- CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedLast);
- if (context != NULL) {
- UIGraphicsPushContext(context);
- // Image 为下载的背景图片,用于比较context
- CGContextTranslateCTM(context, 0, size.height);
- CGContextScaleCTM(context, 1, -1);
- [image drawInRect:imageRect];
- [image2 drawInRect:image2Rect];
- UIGraphicsPopContext();
- CGImageRef imageRef = CGBitmapContextCreateImage(context);
- if (imageRef != NULL) {
- result = [UIImageimageWithCGImage:imageRef];
- CGImageRelease(imageRef);
- }
- CGContextRelease(context);
- }
- free(data);
- }
- return result;
关键方法:
- CGContextRef context = CGBitmapContextCreate();
- CGContextTranslateCTM();
- CGContextScaleCTM();
- CGImageRef imageRef = CGBitmapContextCreateImage(context);
- CGImageRelease(imageRef);
小结:iPhone图形开发绘图教程的内容介绍完了,希望本文对你有所帮助!
Quartz画图函数笔记相关推荐
- matlab二维画图函数汇总--论文,数学建模中使用
一段代码对应相应的图形: %matlab基本画图 clc clear x = linspace(-2*pi,2*pi,100); y = sin(x); %画出基本线条 plot(x,y); %画出多 ...
- Java Lambda 表达式(又名闭包 (Closure)/ 匿名函数 ) 笔记
Java Lambda 表达式(又名闭包 (Closure)/ 匿名函数 ) 笔记 根据 JSR 335, Java 终于在 Java 8 中引入了 Lambda 表达式.也称之为闭包或者匿名函数. ...
- Python3 函数笔记
Python3 函数笔记 默认值在函数定义作用域被解析,如下所示: >>> i =5 >>> def f(arg=i): ... print(arg) .. ...
- 电商第一季函数笔记(1)
1.isset (PHP 4, PHP 5, PHP 7) isset - 检测变量是否设置 说明 bool isset ( mixed $var [, mixed $... ] ) 检测变量是否设置 ...
- python怎么画参数函数图像_详解pandas.DataFrame.plot() 画图函数
首先看官网的DataFrame.plot( )函数 DataFrame.plot(x=None, y=None, kind='line', ax=None, subplots=False, share ...
- oracle concat函数用法_大白的函数笔记:文本合并就是这么简单,不会的快来学...
我们在工作中,经常会遇到需要把几个单元格的内容连接起来的情况,针对这种情况Excel为我们提供了几种方法:CONCATENATE函数.CONCAT函数"&"连接符和PHON ...
- python中plt定义,对Python中plt的画图函数详解
1.plt.legend plt.legend(loc=0)#显示图例的位置,自适应方式 说明: 'best' : 0, (only implemented for axes legends)(自适应 ...
- MATLAB三维画图函数使用总结
简介: 接上一篇,本篇主要是三维画图函数使用总结.在某些数据处理场景中,将数据处理成三维图形会使问题变得更加明晰. 三维绘图函数总结: 代码实现: [注]每个绘图函数都至少有一个使用实例.注意使用时将 ...
- mbedTLS(PolarSSL)简单思路和函数笔记(Client端)
转自: OpenSSL一直以来各种被诟病,具体挑了哪些刺,本文就不深究.作为OpenSSL有很多替代,我了解到的有cyaSSL(WolfSSL)和PolorSSL.其中PolarSSL已经被ARM收购 ...
最新文章
- replication crash safe
- 中国高炉煤气脉冲袋式除尘器市场需求分析与竞争战略规划研究报告2022-2028年版
- 【NOI 2011】阿狸的打字机
- restful接口开发实例_Restful接口开发与测试—接口测试
- 互联网日报 | 6月15日 星期二 | 凯撒旅业拟换股吸并众信旅游;爱回收预计6月18日登陆纽交所;顺丰航空机队规模增至66架...
- 语言程序设计赵山林电子版_【特别策划】崇州“老市长”赵抃系列之一:做官要像江水保持清白...
- day31(GIL锁)
- MegaRAID Storage Manager RAID管理工具实用教程
- 极客大学架构师训练营 系统架构 消息队列 负载均衡 数据库备份 第10课 听课总结
- Sql优化总结!详细!(2021最新面试必问)
- 维谛技术(Vertiv)隆重举行“笃行——数据中心基础设施智能化管理研讨会”...
- 自然辩证法问题思考范围(开卷可用)
- MySQL编程:将查询到的字段赋值给变量
- R语言 第三方软件包的下载及安装
- 在CMD中登陆MySQL
- 安装 SwitchyOmega 最简单的方法
- 大家好,我是新人,请多多关照,(*  ̄3)(ε ̄ *)么么
- 电子听诊器智能化后对健康生活有多大的帮助?
- AndroidQ(10)黑暗模式适配
- 如何看待许多年轻人“疯狂”的投入到IT培训当中
热门文章
- 这款 AI 生成文本工具几分钟即可生成数月社交媒体内容? #Jasper AI
- iTween研究院之学习笔记Move移动篇
- txt格式转换成prg_持批量转换的转换器-dbf converter(dbf文件格式转换器) 官方版 v5.75 - 未来软件园...
- java计算机毕业设计学生信息管理系统源程序+mysql+系统+lw文档+远程调试
- 用CE来找出对对碰游戏 坐位号基址,棋盘数组基址 并把它读出来
- Office word 此文件正由另一应用程序或用户使用的解决方法
- pip 下载速度慢,导致报错:pip._vendor.urllib3.exceptions.ReadTimeoutError……
- android开机音乐
- 初学python小技巧【伯乐在线】
- 深度学习前人精度很高了,该怎么创新?(论文发表,论文创新)