CIGaussianGradient过滤器用于核心图像的示例 [英] An example use of CIGaussianGradient filter for Core Image

查看:242
本文介绍了CIGaussianGradient过滤器用于核心图像的示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找适用于iOS的此Core Image过滤器的代码示例。那些在参数中带有inputImage的过滤器,我可以弄清楚如何实现。但没有inputImage参数的那些,我不知道它是如何工作的。

I am looking for a code sample of this Core Image filter for iOS. Those filters with the inputImage in the parameter, I can figure out how to implement. But the ones without the inputImage parameter, I am not sure how it works.

以下是Apple的文档摘录:

Here is the extract from Apple's doc:

CIGaussianGradient

CIGaussianGradient

使用高斯分布生成从一种颜色到另一种颜色不同的渐变。
参数

Generates a gradient that varies from one color to another using a Gaussian distribution. Parameters

inputCenter

inputCenter

A CIVector class whose attribute type is CIAttributeTypePosition and whose display name is Center.

Default value: [150 150] Identity: (null) 

inputColor0

inputColor0

A CIColor class whose display name is Color 1.

inputColor1

inputColor1

A CIColor class whose display name is Color 2.

inputRadius

inputRadius

An NSNumber class whose attribute type is CIAttributeTypeDistance and whose display name is Radius.

Default value: 300.00 Minimum: 0.00 Maximum: 0.00 Slider minimum: 0.00 Slider maximum: 800.00 Identity: 300.00


推荐答案

这应该让你开始......虽然我不知道为什么这会在iOS中产生洋红色白色渐变,而它会产生黑色洋红色Quartz Composer中的渐变。 (如果您还没有使用过Quartz Composer,它包含在Apple的开发工具中,非常适合测试Core Image过滤器)

This should get you started... though I'm not sure why this produces a magenta over white gradient in iOS, while it produces a magenta over black gradient in Quartz Composer. (if you haven't used Quartz Composer, it's included with Apple's dev tools and is great for testing out Core Image filters)

要做任何有用的事情,我相信你必须在之后裁剪它 - 否则它将具有无限的尺寸(根据Quartz Composer)。

To do anything useful with it, I believe you have to crop it afterwards - otherwise it will have infinite dimensions (according to Quartz Composer).

// set up the parameters for the filter
CIVector *centerVector = [CIVector vectorWithX:150 Y:150];
CIColor *color0 = [CIColor colorWithRed:1.0 green:0.0 blue:1.0 alpha:1.0];
CIColor *color1 = [CIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
NSNumber *radius = [NSNumber numberWithFloat:300.0];

// create a CIImage and apply the filter
CIImage *theCIImage = [[CIImage alloc] init];
theCIImage = [CIFilter filterWithName:@"CIGaussianGradient" keysAndValues:@"inputCenter", centerVector, @"inputColor0", color0, @"inputColor1", color1, @"inputRadius", radius, nil].outputImage;

// crop the image using CICrop
CGRect rect = CGRectMake(0.0, 0.0, 600.0, 600.0);
theCIImage = [CIFilter filterWithName:@"CICrop" keysAndValues:kCIInputImageKey, theCIImage, @"inputRectangle", rect, nil].outputImage;

这篇关于CIGaussianGradient过滤器用于核心图像的示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆