OGeek|极客世界-中国程序员成长平台

标题: ios - 一个使用 CIGaussianGradient 过滤器的 Core Image 示例 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 09:45
标题: ios - 一个使用 CIGaussianGradient 过滤器的 Core Image 示例

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

这是苹果文档的摘录:

CIGaussianGradient

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

输入中心

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

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

输入颜色0

A CIColor class whose display name is Color 1.

输入颜色1

A CIColor class whose display name is Color 2.

输入半径

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



Best Answer-推荐答案


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

要使用它做任何有用的事情,我相信您必须在之后对其进行裁剪 - 否则它将具有无限维度(根据 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;

关于ios - 一个使用 CIGaussianGradient 过滤器的 Core Image 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8031785/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4