Core Image

使用滤镜的步骤:

  1. 创建滤镜CIFilter对象
  2. 设置滤镜参数
  3. 输出结果
    官方Guider:
    官方链接
    直接上代码:
UIImage *img = [UIImage imageNamed:@"dog"];

CGImageRef cgImg = [img CGImage];

CIImage *ciImg = [CIImage imageWithCGImage:cgImg];

CIContext *context = [CIContext contextWithOptions:nil];    //渲染上下文,GPU或者CPU来渲染,在ios中,nil参数代表GPU或CPU,可理解为CIContext为渲染引擎,即GPU或CPU

CIFilter *hueAdjust = [CIFilter filterWithName:@"CIHueAdjust"];   //CIFilter为滤镜

[hueAdjust setValue: ciImg forKey: kCIInputImageKey];

[hueAdjust setValue: @2.094f forKey: kCIInputAngleKey];

CIImage *result = [hueAdjust valueForKey: kCIOutputImageKey];

CGImageRef imgRef = [context createCGImage: result fromRect: CGRectMake(0, 0,  img.size.width * img.scale, img.size.height * img.scale)];

UIImage *tempImg = [UIImage imageWithCGImage:imgRef scale:2 orientation:UIImageOrientationUp];

运行结果:
这里写图片描述

CIContext
To render the image, you need to create a Core Image context and then use that context to draw the output image. A Core Image context represents a drawing destination. The destination determines whether Core Image uses the GPU or the CPU for rendering.
可以把CIContext理解为渲染图像的GPU或CPU

重点对象

CIFilter
滤镜对象:将所有参数放入该对象中。
filterWithName:该方法生成CIFilter对象,参数是固定的,传入需要使用的滤镜类型。
setValue: forKey:该方法设置滤镜属性的值
CIImage *result = [hueAdjust valueForKey: kCIOutputImageKey];获得滤镜输出的CIImage图像,将其转换为CGImageRef,然后显示。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值