Transforms CTM, 转换矩阵
来源:互联网 发布:7层网络协议 http 编辑:程序博客网 时间:2024/05/21 11:09
Quartz转换实现的原理:Quartz把绘图分成两个部分,
用户空间,即和设备无关,
设备空间,
用户空间和设备空间中间存在一个转换矩阵 : CTM
本章实质是讲解CTM
Quartz提供的3大功能
移动,旋转,缩放
演示如下,首先加载一张图片
void CGContextDrawImage (
CGContextRef c,
CGRect rect,
CGImageRef image
);
移动函数
CGContextTranslateCTM (myContext, 100, 50);
旋转函数
include <math.h>
static inline double radians (double degrees) {return degrees * M_PI/180;}
CGContextRotateCTM (myContext, radians(–45.));
缩放
CGContextScaleCTM (myContext, .5, .75);
翻转, 两种转换合成后的效果,先把图片移动到右上角,然后旋转180度
CGContextTranslateCTM (myContext, w,h);
CGContextRotateCTM (myContext, radians(-180.));
组合几个动作
CGContextTranslateCTM (myContext, w/4, 0);
CGContextScaleCTM (myContext, .25, .5);
CGContextRotateCTM (myContext, radians ( 22.));
CGContextRotateCTM (myContext, radians ( 22.));
CGContextScaleCTM (myContext, .25, .5);
CGContextTranslateCTM (myContext, w/4, 0);
上面是通过直接修改当前的ctm实现3大效果,下面是通过创建Affine Transforms,然后连接ctm实现同样的3种效果
这样做的好处是可以重用这个Affine Transforms
应用Affine Transforms 到ctm的函数
void CGContextConcatCTM (
CGContextRef c,
CGAffineTransform transform
);
Creating Affine Transforms
移动效果
CGAffineTransform CGAffineTransformMakeTranslation (
CGFloat tx,
CGFloat ty
);
CGAffineTransform CGAffineTransformTranslate (
CGAffineTransform t,
CGFloat tx,
CGFloat ty
);
旋转效果
CGAffineTransform CGAffineTransformMakeRotation (
CGFloat angle
);
CGAffineTransform CGAffineTransformRotate (
CGAffineTransform t,
CGFloat angle
);
缩放效果
CGAffineTransform CGAffineTransformMakeScale (
CGFloat sx,
CGFloat sy
);
CGAffineTransform CGAffineTransformScale (
CGAffineTransform t,
CGFloat sx,
CGFloat sy
);
反转效果
CGAffineTransform CGAffineTransformInvert (
CGAffineTransform t
);
只对局部产生效果
CGRect CGRectApplyAffineTransform (
CGRect rect,
CGAffineTransform t
);
判断两个AffineTrans是否相等
bool CGAffineTransformEqualToTransform (
CGAffineTransform t1,
CGAffineTransform t2
);
获得Affine Transform
CGAffineTransform CGContextGetUserSpaceToDeviceSpaceTransform (
CGContextRef c
);
下面的函数只起到查看的效果,比如看一下这个用户空间的点,转换到设备空间去坐标是多少
CGPoint CGContextConvertPointToDeviceSpace (
CGContextRef c,
CGPoint point
);
CGPoint CGContextConvertPointToUserSpace (
CGContextRef c,
CGPoint point
);
CGSize CGContextConvertSizeToDeviceSpace (
CGContextRef c,
CGSize size
);
CGSize CGContextConvertSizeToUserSpace (
CGContextRef c,
CGSize size
);
CGRect CGContextConvertRectToDeviceSpace (
CGContextRef c,
CGRect rect
);
CGRect CGContextConvertRectToUserSpace (
CGContextRef c,
CGRect rect
);
CTM真正的数学行为
这个转换矩阵其实是一个 3x3的 举证
如下图
下面举例说明几个转换运算的数学实现
x y 是原先点的坐标
下面是从用户坐标转换到设备坐标的计算公式
下面是一个identity matrix,就是输入什么坐标,出来什么坐标,没有转换
最终的计算结果是 x=x,y=y,
可以用函数判断这个矩阵是不是一个 identity matrix
bool CGAffineTransformIsIdentity (
CGAffineTransform t
);
移动矩阵
缩放矩阵
旋转矩阵
旋转加移动矩阵
参考:http://developer.apple.com/iphone/library/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_affine/dq_affine.html#//apple_ref/doc/uid/TP30001066-CH204-SW1
原文地址:http://donbe.blog.163.com/blog/static/138048021201061054243442/
- Transforms CTM, 转换矩阵
- Transforms CTM, 转换矩阵
- Transforms CTM 转换矩阵
- Transforms CTM, 转换矩阵
- Transforms CTM, 转换矩阵
- Transforms CTM, 转换矩阵
- Transforms CTM, 转换矩阵
- Transforms CTM, 转换矩阵
- Transforms CTM 转换矩阵
- Transforms CTM, 转换矩阵
- Quartz Transforms CTM, 转换矩阵
- transforms CTM,变换矩阵
- iphone开发——Transforms CTM, 转换矩阵
- 1.9. 坐标转换 Coordinate Transforms
- Transforms
- 关于TF转换信息(Transforms)的理解
- CTM(绘图)
- 矩阵转换
- 半秒内筛一亿以内的所有素数
- 红黑树(一) 插入
- qmake 乱乱乱谈(一)
- 如果你的男朋友是这样 请你离开。女朋友同理 (很经典请牢记)
- 添加菜单遇到的问题引出的linux下gksu和sudo的分别
- Transforms CTM, 转换矩阵
- 关于android的资料
- Android控件解析
- 上vdfas飞
- 将QNX应用上传到QNX虚拟机上
- 毕业前的第一次笔试总结
- 红黑树(二)删除
- java设计模式---singleton---单例模式
- android 命令行模式启动模拟器