Quartz

来源:互联网 发布:html5整站源码 编辑:程序博客网 时间:2024/04/28 16:35
Transforms CTM, 转换矩阵
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);