iOS Developer

图形图象及动画

2017-07-05  本文已影响31人  CoderLWG

1、UIImage显示静止图片的类方法

* +imageNamed: 该方法有缓存机制,如果需要频繁的加载卸载图片时,不应该使用该方法
* + imageWithContentOfFile: 该方法加载指定文件名对应的图片
* + imageWithData:
* + imageWithData:scale: 指定缩放因子对图片进行缩放
* + imageWithCGImages:根据指定的CGImageRef对象来创建UIImage
* + imageWithCGImages:scale:orientation:
* + animatedImageNamed:duration: 根据指定的图片名在加载系列图片
* + animatedImageWithImages:duration: 该方法需要传入一个NSArray作为多张动画图片

动画效果

CGAffineTransform CGAffineTransformMake (

CGFloat a,

CGFloat b,

CGFloat c,

CGFloat d,

CGFloat tx,

CGFloat ty );

//创建一个给定比例放缩的变换
CGAffineTransformMakeScale (CGFloat sx, CGFloat sy);   

CGAffineTransformMakeScale(-1.0, 1.0);//水平翻转
CGAffineTransformMakeScale(1.0,-1.0);//垂直翻转
//创建一个旋转角度的变化
CGAffineTransform CGAffineTransformMakeRotation ( CGFloat angle); 
//创建一个平移的变化
CGAffineTransform CGAffineTransformMakeTranslation (CGFloat tx,CGFloat ty);
img

六个参数对应矩阵的前两列。

- (void)transformImageView

{

CGAffineTransform t = CGAffineTransformMakeScale(scale * previousScale,

scale * previousScale);

t = CGAffineTransformRotate(t, rotation + previousRotation);

self.imageView.transform = t;

}

// 绘制复杂的图形,必须启用路径


在Canvas(画布)中使用路径,可按如下步骤进行

在内存中绘图

步骤如下

图形变换

Quartz 2D提供如下坐标变换

使用矩阵变换

Core Image 滤镜

三个核心API

// 第一种创建方式:基于CPU的CIContext对象
    CIContext *ctx = [CIContext contextWithOptions:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],kCIContextUseSoftwareRenderer, nil]];
    // 第二种创建方式:基于GPU的CIContext对象
    ctx = [CIContext contextWithOptions:nil];
    // 第三种方式:基于OpenGL优化的对象
    EAGLContext *eaglctx = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];

2.创建CIFilter过滤器,CIFilter提供了filterWithName:类方法来创建CIFilter对象,该方法需要传入过滤器的名字
滤镜名字查询

NSArray *names = [CIFilter filterNamesInCategory:kCICategoryBuiltIn];
NSLog(@"%@",names);

通过打印可以获取滤镜的所有名字
3.创建CIImage对象
4.调用CIFilter的setValue方法为inputImage属性复制

  [filter setValue:image forKey:kCIInputImageKey];
   [filter setValue:[CIColor colorWithRed:100/255 green:0.4 blue:1] forKey:kCIInputColorKey];

5.根据需要,为不同的滤镜设置不同的过滤参数
6.调用CIFilter的outputImage方法获取处理后的图片

Core Animation动画基础

使用core animaton创建动画,不仅简单而且具有更好的性能,原因如下:

Core Animation动画还涉及如下API

上一篇 下一篇

猜你喜欢

热点阅读