gpt4 book ai didi

ios - CIGaussianGradient 过滤器用于 Core Image 的示例

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:18:01 24 4
gpt4 key购买 nike

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

这是 Apple 文档的摘录:

CI高斯梯度

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

输入中心

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

最佳答案

这应该可以让您开始……虽然我不确定为什么这会在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com